rename Dynamic Programming -> dynamic_programming (#645)

* rename Dynamic Programming -> dynamic_programming

* rename dynamic-programming -> dynamic_programming
This commit is contained in:
Christian Clauss
2019-11-28 13:29:01 +01:00
committed by GitHub
parent fc7e416030
commit 5c241487aa
16 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
//Program to calculate length of longest increasing subsequence in an array
#include <bits/stdc++.h>
using namespace std;
int LIS(int a[], int n)
{
int lis[n];
for (int i = 0; i < n; ++i)
{
lis[i] = 1;
}
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < i; ++j)
{
if (a[i] > a[j] && lis[i] < lis[j] + 1)
lis[i] = lis[j] + 1;
}
}
int res = 0;
for (int i = 0; i < n; ++i)
{
res = max(res, lis[i]);
}
return res;
}
int main(int argc, char const *argv[])
{
int n;
cout << "Enter size of array: ";
cin >> n;
int a[n];
cout << "Enter array elements: ";
for (int i = 0; i < n; ++i)
{
cin >> a[i];
}
cout << LIS(a, n) << endl;
return 0;
}