Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int I[2003],D[2003],sequence[2003];
- int n;
- int main()
- {
- int i,j,res,test;
- scanf("%d",&test);
- while(test--)
- {
- scanf("%d",&n);
- for(i=0;i<n;i++)
- {
- scanf("%d",&sequence[i]);
- }
- for(i=0;i<n;i++)
- {
- I[i] = D[i] = 1;
- }
- for(i=n-1;i>=0;i--)
- {
- for(j=n-1;j>i;j--)
- {
- if(sequence[i]>sequence[j])
- {
- I[i] = max(I[i],I[j]+1);
- }
- else if(sequence[i]<sequence[j])
- {
- D[i] = max(D[i],D[j]+1);
- }
- }
- }
- res = 0;
- for(i=0;i<n;i++)
- {
- res = max(res,I[i]+D[i]-1);
- }
- printf("%d\n",res);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment