diff --git a/Contributors.md b/Contributors.md index bb585a2..fa5b727 100644 --- a/Contributors.md +++ b/Contributors.md @@ -38,3 +38,4 @@ * [Muskan](https://github.com/Muskan-goyal6) * [Tarannum](https://github.com/giTan7) * [HCamberos](https://github.com/HCamberos) +* [Ankit Bhadage](https://github.com/Ankitmb125) diff --git a/Dynamic Programming/floydWarshall.cpp b/Dynamic Programming/floydWarshall.cpp new file mode 100644 index 0000000..dbe917b --- /dev/null +++ b/Dynamic Programming/floydWarshall.cpp @@ -0,0 +1,61 @@ +/*The Floyd Warshall Algorithm is for solving the All Pairs Shortest Path problem. The problem is to find shortest distances between every pair of vertices in a given edge weighted directed Graph.*/ + +#include +using namespace std; + +#define V 4 + +#define INF 99999 + +void printSolution(int dist[][V]); + +void floydWarshall (int graph[][V]) +{ + int dist[V][V], i, j, k; + + for (i = 0; i < V; i++) + for (j = 0; j < V; j++) + dist[i][j] = graph[i][j]; + for (k = 0; k < V; k++) + { + for (i = 0; i < V; i++) + { + for (j = 0; j < V; j++) + { + if (dist[i][k] + dist[k][j] < dist[i][j]) + dist[i][j] = dist[i][k] + dist[k][j]; + } + } + } + + printSolution(dist); +} + +void printSolution(int dist[][V]) +{ + cout<<"The following matrix shows the shortest distances" + " between every pair of vertices \n"; + for (int i = 0; i < V; i++) + { + for (int j = 0; j < V; j++) + { + if (dist[i][j] == INF) + cout<<"INF"<<" "; + else + cout< +using namespace std; + +int lis( int arr[], int n ) +{ + int lis[n]; + + lis[0] = 1; + + for (int i = 1; i < n; i++ ) + { + lis[i] = 1; + for (int j = 0; j < i; j++ ) + if ( arr[i] > arr[j] && lis[i] < lis[j] + 1) + lis[i] = lis[j] + 1; + } + + return *max_element(lis, lis+n); +} + +int main() +{ + int arr[] = { 10, 22, 9, 33, 21, 50, 41, 60 }; + int n = sizeof(arr)/sizeof(arr[0]); + printf("Length of lis is %d\n", lis( arr, n ) ); + return 0; +}