Josif_tepe

Untitled

Dec 9th, 2025
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. typedef long long ll;
  7. const int maxn = 2505;
  8. int n, a[maxn];
  9.  
  10. int rec(int at) {
  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.     cin >> n;
  23.    
  24.     for(int i = 0; i < n; i++) {
  25.         cin >> a[i];
  26.     }
  27.     int res = 0;
  28.     for(int i = 0; i < n; i++) {
  29.         res = max(res, rec(i));
  30.     }
  31.    
  32.     cout << res << endl;
  33.    
  34.     return 0;
  35. }
  36.  
  37. // 10 9 2 5 3 7 101 18
  38. // 0 1 0 3 2 3
  39. // 7 7 7 7 7 7 7
  40.  
Advertisement
Add Comment
Please, Sign In to add comment