Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- int n;
- int a[2501];
- int dp[2501];
- int rec(int at) {
- if(dp[at] != -1) {
- return dp[at];
- }
- int res = 0;
- for(int i = at + 1; i < n; i++) {
- if(a[at] < a[i]) {
- res = max(res, rec(i) + 1);
- }
- }
- dp[at] = res;
- return res;
- }
- int main() {
- cin >> n;
- memset(dp, -1, sizeof dp);
- for(int i = 0; i < n; i++) {
- cin >> a[i];
- }
- int res = 0;
- for(int i = 0; i < n; i++) {
- res = max(res, rec(i) + 1);
- }
- cout << res << endl;
- // 10 9 2 5 3 7 101 18
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement