longest ordered subsequence

本文介绍了一种寻找序列中最长递增子序列的算法实现,不仅计算了最长子序列的长度,还记录了子序列中的元素。通过动态规划方法,结合辅助数组追踪前驱元素索引,最终实现了完整子序列的重构。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值