Font Size: aaaaaade133
Returns a sequence x [1. n] consisting of n numbers, and finds the length of its longest monotonic ascending subsequence. Find the maximum length of m and a1, a2 ......, Am, making a1 <a2 <... ... <Am and x [a1] <x [a2] <... ... <X [am]. Input
Enter an integer t (t <= 200) to represent the number of test groups. Enter N for each group of data, which indicates N numbers (1 <= N <= 1000 ). enter N positive integers, a1, a2, a3 ..... an (0 <= ai <= 100000 ). Output
Each group outputs an integer representing the longest length. Sample Input
171 7 3 5 9 4 8 Sample Output
4
The Code is as follows:#include #define maxn 1005int a[maxn]; int dp[maxn]; int max(int x,inty){ returnx>y?x:y;} int main() { intt,n; scanf("%d",&t); while(t--) { scanf("%d",&n); inti,j; for(i=1;i<=n;i++) scanf("%d",&a[i]); for(i=0;i<=n;i++) dp[i]=1; intans=0; for(i=1;i<=n;i++) { for(j=1;j < code> if (a[j] dp[i]=max(dp[i],dp[j]+1); ans=max(dp[i],ans); } printf("%d\n",ans); } return0;} <> |