标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1427 Accepted Submission(s): 489
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; const int N = 1005; int dp[N],num[N]; int a[N]; int main(){ int tcase; scanf("%d",&tcase); while(tcase--){ int n; scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d",&a[i]); } int ans = dp[1] = num[1]= 1; for(int i=2;i<=n;i++){ dp[i] =num[i]= 1; for(int j=1;j<i;j++){ if(a[i]>a[j]){ if(dp[i]==dp[j]+1){ num[i]+=num[j]; } if(dp[i]<dp[j]+1){ dp[i] = dp[j]+1; num[i] = num[j]; } } } ans = max(ans,dp[i]); } int cnt=0; for(int i=1;i<=n;i++){ if(dp[i]==ans){ cnt+=num[i]; } } if(cnt==1) printf("%d\n",ans-1); else printf("%d\n",ans); } return 0; }
标签:
原文地址:http://www.cnblogs.com/liyinggang/p/5658541.html