Font Size: aaaaaade133Returns 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]. InputEnter 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 ). OutputEach group outputs an integer representing the longest length. Sample Input171 7 3 5 9 4 8 Sample Output4
The Code is as follows:#include #define maxn 1005 int a[maxn]; int dp[maxn]; int max( int x, int y) { return x>y?x:y; } int main() { int t,n; scanf ( "%d" ,&t); while (t--) { scanf ( "%d" ,&n); int i,j; for (i=1;i<=n;i++) scanf ( "%d" ,&a[i]); for (i=0;i<=n;i++) dp[i]=1; int ans=0; for (i=1;i<=n;i++) { for (j=1;j if (a[j] dp[i]=max(dp[i],dp[j]+1); ans=max(dp[i],ans); } printf ( "%d\n" ,ans); } return 0; } |