longest ordered subsequence

来源:互联网 发布:新中新身份证阅读软件 编辑:程序博客网 时间:2024/05/16 12:51

Given a sequence with many elements and find the ordered subseqence from the original sequence.

dp[i] means the longest length starting from begin of sequence to element i.

dp[i]=max{dp[j]+1,dp[i]} for 0<=j<i and a[i]<a[j]

pku 2533

the original problem only need find the longest length but the elements in the subsequence cannot be acquried.

in my solution, i add a array to record the previous element index of the current element in the subsequence. after find the longest length of the subsequence we can use the array to find all the element index in the subsequence so that we can get all the elements in the subsequence.

原创粉丝点击