Advertisement
Saleh127

Light OJ 1283 / DP - Interval

Sep 20th, 2022
739
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. /***
  2.  created: 2022-09-21-03.18.37
  3. ***/
  4.  
  5. #include <bits/stdc++.h>
  6. #include <ext/pb_ds/assoc_container.hpp>
  7. #include <ext/pb_ds/tree_policy.hpp>
  8. using namespace std;
  9. using namespace __gnu_pbds;
  10. template<typename U> using ordered_set=tree<U, null_type,less<U>,rb_tree_tag,tree_order_statistics_node_update>;
  11. #define ll long long
  12. #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
  13. #define get_lost_idiot return 0
  14. #define nl '\n'
  15.  
  16. ll dp[101][101][101];
  17. ll a[102],n;
  18.  
  19. ll solve(ll in,ll l,ll r)
  20. {
  21.     if(in>n) return 0;
  22.  
  23.     if(dp[in][l][r]!=-1) return dp[in][l][r];
  24.  
  25.     ll ans=solve(in+1,l,r);
  26.  
  27.     if(a[in]>=a[l] && a[in]<=a[r])
  28.     {
  29.         ans=max(ans,max( solve(in+1,in,r)+1, solve(in+1,l,in)+1 ));
  30.     }
  31.     return dp[in][l][r]=ans;
  32. }
  33.  
  34. int main()
  35. {
  36.     ios_base::sync_with_stdio(0);
  37.     cin.tie(0);
  38.     cout.tie(0);
  39.  
  40.  
  41.     test
  42.     {
  43.         ll i,j,k,l;
  44.  
  45.         cin>>n;
  46.  
  47.         for(i=1;i<=n;i++) cin>>a[i];
  48.  
  49.         memset(dp,-1,sizeof dp);
  50.  
  51.         a[0]=0;
  52.         a[n+1]=1e15;
  53.  
  54.         cout<<"Case "<<cs<<": "<<solve(1,0,n+1)<<nl;
  55.     }
  56.  
  57.  
  58.     get_lost_idiot;
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement