Advertisement
Josif_tepe

Untitled

Nov 20th, 2024
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <queue>
  4. #include <cmath>
  5. using namespace std;
  6. const int maxn = 100;
  7. int n, arr[maxn];
  8. int dp[maxn];
  9. int rec(int at) {
  10.     if(dp[at] != -1) {
  11.         return dp[at];
  12.     }
  13.    
  14.     int res = 0;
  15.    
  16.     for(int i = at + 1; i < n; i++) {
  17.         if(arr[at] < arr[i]) {
  18.             res = max(res, rec(i) + 1);
  19.         }
  20.     }
  21.    
  22.     return dp[at] = res;
  23. }
  24. int main() {
  25.     cin >> n;
  26.    
  27.     for(int i = 0; i < n; i++) {
  28.         cin >> arr[i];
  29.     }
  30.    
  31.     for(int i = 0; i < maxn; i++) {
  32.         dp[i] = -1;
  33.     }
  34.    
  35.     int res = 0;
  36.     for(int i = 0; i < n; i++) {
  37.         res = max(res, rec(i) + 1);
  38.     }
  39.     cout << res << endl;
  40.    
  41.     return 0;
  42. }
  43. // fib(4) = fib(3) + fib(2) = 2 + 1 = 3
  44. // fib(3) = fib(2) + fib(1) = 1 + 1 = 2
  45. // fib(2) = 1
  46. // fib(1) = 1
  47. // fib(2) = 1
  48.  
  49.  
  50. // 7 7 7 7 7 7 7
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement