Advertisement
Josif_tepe

Untitled

Oct 15th, 2021
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int n;
  5.  
  6. int niza[105];
  7. int dp[100];
  8. int l(int i){
  9.     if(dp[i]!=-1){
  10.         return dp[i];
  11.     }
  12.     int ss=0;
  13. for(int k=i+1; k<n; k++){
  14.   if(niza[i]>=niza[k]){
  15.     ss=max(ss, l(k)+1);
  16.   }
  17. }
  18.  
  19. dp[i]=ss;
  20. return dp[i];
  21. }
  22. int main()
  23. {
  24. cin>>n;
  25. for(int i=0; i<n; i++){
  26.     cin>>niza[i];
  27.     dp[i]=-1;
  28. }
  29. int ss=0;
  30. for(int i=0; i<n; i++){
  31.    ss=max(ss, l(i)+1);
  32. }
  33. cout<<ss<<endl;
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement