Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9f65c44

Browse files
Longest increasing subsequence
1 parent 39a7a64 commit 9f65c44

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* Amit Bansal - @amitbansal7 */
2+
#include <bits/stdc++.h>
3+
#define INF 0x3f3f3f3f
4+
using namespace std;
5+
//Longest increasing subsequence
6+
7+
int main()
8+
{
9+
int seq[] = {3, 4, -1, 0, 6, 2, 3};
10+
int n = sizeof(seq) / sizeof(seq[0]);
11+
12+
int DP[n];
13+
for (int i = 0; i < n; i++)
14+
DP[i] = 1;
15+
16+
for (int i = 1; i < n; i++)
17+
for (int j = 0; j < i; j++)
18+
if (seq[j] < seq[i])
19+
DP[i] = max(DP[i], DP[j] + 1);
20+
21+
int maxn = INT_MIN;
22+
23+
for (int i = 0; i < n; i++)
24+
if (maxn < DP[i])
25+
maxn = DP[i];
26+
27+
printf("%d\n", maxn);
28+
29+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /