Advertisement
Josif_tepe

Untitled

May 12th, 2025
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. int n;
  6. int a[2501];
  7. int dp[2501];
  8. int rec(int at) {
  9.     if(dp[at] != -1) {
  10.         return dp[at];
  11.     }
  12.     int res = 0;
  13.    
  14.     for(int i = at + 1; i < n; i++) {
  15.         if(a[at] < a[i]) {
  16.             res = max(res, rec(i) + 1);
  17.         }
  18.     }
  19.     dp[at] = res;
  20.     return res;
  21. }
  22. int main() {
  23.     cin >> n;
  24.     memset(dp, -1, sizeof dp);
  25.     for(int i = 0; i < n; i++) {
  26.         cin >> a[i];
  27.     }
  28.    
  29.     int res = 0;
  30.     for(int i = 0; i < n; i++) {
  31.         res = max(res, rec(i) + 1);
  32.     }
  33.     cout << res << endl;
  34.    
  35.     // 10 9 2 5 3 7 101 18
  36.    
  37.     return 0;
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement