序列问题II
Time Limit: 1000 MS Memory Limit: 32768 K
Total Submit: 202(90 users) Total Accepted: 95(83 users) Rating: Special Judge: No
Description
给一个长度为n的整数序列A0,A1,……An-1,找出最长的非递增子序列的长度
Input
输入第一行为数据组数T(T<=20)。
每组数据的第一行为整数的个数n(2<=n<=1000),第二行为n个绝对值不超过150000的整数。
Output
对于每组数据,输出最长的非递增子序列的长度。
Sample Input
2
3
1 1 3
4
-1 4 3 2
Sample Output
2
3
Author
陈禹@HRBUST
#include<stdio.h>
#include<string.h>
int main()
{
int t;
int a[10003];
int dp[10003];
scanf("%d",&t);
while(t--)
{
memset(dp,0,sizeof(dp));
int n;
scanf("%d",&n);
for(int i=0; i<n; i++)
{
scanf("%d",&a[i]);
}
dp[0]=0;
for(int i=0; i<n-1; i++)
{
for(int j=i+1; j<n; j++)
{
if(a[i]>=a[j])
{
//printf("%d %d ",a[i],a[j]);
if(dp[j]<dp[i]+1)
dp[j]=dp[i]+1;
// printf("%d: %d\n",j,dp[j]);
}
}
}
int max=0;
for(int i=0; i<n; i++)
if(dp[i]>max)max=dp[i];
printf("%d\n",max+1);
}
}