核心代码
//dp[i]:以第i个串为结尾的最长上升子序列长度
for(int i=1;i<cnt;i++){
string now=a[i];
if(!tot||now>tmp[tot]) tmp[++tot]=now,dp[i]=tot;
else{
int l=1,r=tot;
//第一个比now大的
while(l<r){
int m=(l+r)>>1;
if(tmp[m]<=now) l=m+1;
else r=m;
}
tmp[l]=now;
dp[i]=l;
}
}
ps(string重载实现)
bool operator > (string a,string b){
if(a.compare(b)<=0) return false;
return true;
}
该博客介绍了如何使用动态规划求解最长上升子序列问题。核心代码展示了如何维护一个有序字符串数组,并通过二分查找优化更新过程,提高算法效率。

被折叠的 条评论
为什么被折叠?



