DP--Longest Ordered Subsequence

来源:互联网 发布:网络黑侠哪本作品好 编辑:程序博客网 时间:2024/06/10 22:54
A numeric sequence of ai is ordered ifa1<</b> a2 < ... <</b>aN. Let thesubsequence of the given numeric sequence (a1,a2, ...,aN) be anysequence ( ai1, ai2, ...,aiK), where 1 <=i1<</b> i2 < ... <</b>iK <=N. For example, sequence (1, 7, 3, 5, 9, 4, 8) hasordered subsequences, e. g., (1, 7), (3, 4, 8) and many others. Alllongest ordered subsequences are of length 4, e. g., (1, 3, 5,8).

Your program, when given the numeric sequence, must find the lengthof its longest ordered subsequence.
Input
The first line of input filecontains the length of sequence N. The second line contains theelements of sequence - N integers in the range from 0 to 10000each, separated by spaces. 1 <= N <= 1000
Output
Output file must contain asingle integer - the length of the longest ordered subsequence ofthe given sequence.
Sample Input
71 7 3 5 9 4 8
Sample Output
4
输出最长递增子序列的长度
典型dp
状态是每项对应由此项以前的数列可以组成的最长递增子序列个数,状态转移方程:
state(i)=max(state(从1到i-1中比seq[I]小的项))+1;
问题是这题居然只有一组测试数据,害我对着OLE纳闷半天
用seq[n]存储数列,用dp[n]存储state
http://paste.ubuntu.com/23980211/
0 0
原创粉丝点击