Skip to content

Instantly share code, notes, and snippets.

@tchomphoochan
Last active March 7, 2019 16:00
Show Gist options
  • Save tchomphoochan/391dcdd9c4bba845fbfda9c8d89046f5 to your computer and use it in GitHub Desktop.
Save tchomphoochan/391dcdd9c4bba845fbfda9c8d89046f5 to your computer and use it in GitHub Desktop.
int A[MAX_N]; // assume data is in A[1..n]
int dp[MAX_N];
int ans = 0;
for (int i = 1; i <= n; ++i) {
dp[i] = 1;
for (int j = 1; j < i; ++j) {
if (A[j] < A[i])
dp[i] = max(dp[i], 1+dp[j]);
}
ans = max(ans, dp[i]);
}
cout << ans << endl;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment