Josif_tepe

Untitled

Dec 23rd, 2025
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4. const int maxn = 2502;
  5.  
  6. int n;
  7. int a[maxn];
  8.  
  9. int rec(int at) {
  10.    
  11.     int res = 1;
  12.    
  13.     for(int i = at + 1; i < n; i++) {
  14.         if(a[at] < a[i]) {
  15.             res = max(res, rec(i) + 1);
  16.         }
  17.     }
  18.    
  19.     return res;
  20. }
  21. int main() {
  22.  
  23.     cin >> n;
  24.    
  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));
  32.     }
  33.    
  34.     cout << res << endl;
  35.     return 0;
  36. }
  37. // rec(0) = rec(6) + 1 = 2
  38. // rec(0) = rec(7) + 1 = 2
  39. // rec(6) = 1
  40. // rec(7) = 1
  41.  
Advertisement
Add Comment
Please, Sign In to add comment