No.58-leetcode646-最长上升对的链
发布日期:2021-07-28 02:54:28 浏览次数:8 分类:技术文章

本文共 761 字,大约阅读时间需要 2 分钟。

和最长上升子序列相同:

不过先排个序

class Solution {public:    static bool cmp(const vector
& a,const vector
& b){ if(a[1] < b[1]) return true; if(a[1] == b[1] && a[0] < b[0]) return true; return false; } int findLongestChain(vector
>& pairs) { int N = pairs.size(); sort(pairs.begin(),pairs.end(),cmp); int dp[N+1]; memset(dp,0xc0,sizeof(dp)); int mx = 1; for(int i=0;i
dp[j]){ if(j==mx-1){ dp[mx++] = pairs[i][1]; break; }else{ dp[j+1] = min(dp[j+1],pairs[i][1]); } } } } return mx-1; }};

转载地址:https://blog.csdn.net/ShellDawn/article/details/99327436 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:No.59 - LeetCode1140 - 动态规划 - 很难
下一篇:内存:进程调度

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月26日 19时26分39秒