![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
lcs、lis
Sor4
这个作者很懒,什么都没留下…
展开
-
light oj 1013 LCS 应用
题意:给定两个字符串A,B,要求求一个字符串S,使得A,B是S 的子串,求S 的最小长度,以及在此长度下有多少种构成S 的方案。LCS的变形,S的最小长度肯定是A+B的长度-A和B的最长公共组序列的长度。之后的方案用DP思想去写就可以了。QAQ 我也是看了题解才会写的。先用lcs 去求A和B 的最长公共子序列。然后dp[i][j][k]表示构造了i长度的字符串,在利用了A串的前j个字符原创 2015-08-07 14:40:10 · 422 阅读 · 0 评论 -
poj 1631 LIS nlogn算法
题意:给出n个点,分别和1~n相连构成相交线段,现在要去几条线段,要求剩下的线段不想交,且不相交的线段数量最多。因为p#include #include #include #pragma warning(disable :4996)using namespace std;const int Max = 40005;int c[Max];int Binary(int l,原创 2015-08-09 14:48:51 · 335 阅读 · 0 评论 -
poj 1458 LCS
#include #include #include #pragma warning (disable :4996)using namespace std;const int Max = 1000;int dp[Max][Max];char str1[Max], str2[Max];int LCS(int lenstr1, int lenstr2){ memset(dp,原创 2015-08-07 16:31:13 · 250 阅读 · 0 评论 -
poj 1080 LCS 应用
题意:给定两个DNA序列,然后按照给出的表格进行匹配,求匹配的最大值,利用lcs 原理,不过加了权值,就不能再像之前那样进行匹配了,但是原理是一样的。因为有‘-’的存在,所以这边要先对边界进行处理一下。因为带权值,所以求得的不一定会是最长公共子序列,所以就不用判断str1[i]==str2[j]这种条件了。转移方程:dp[i][j]表示的是str1从0~i-1和str2从0~j-1 匹原创 2015-08-12 14:47:06 · 257 阅读 · 0 评论 -
cf 10D lcis 最长上升子序列+输出路径
用个数组记录下路径然后dfs 输出就可以了#include #include #include #pragma warning (disable : 4996)using namespace std;const int Max = 505;int dp[Max][Max], pre[Max][Max];int a[Max], b[Max];int m, n;void df原创 2015-08-12 19:48:48 · 377 阅读 · 0 评论 -
light oj 1110 LCS 记录路径
#include #include #include #pragma warning (disable : 4996)using namespace std;const int Max = 105;int dp[Max][Max];char s[Max][Max][Max];char str1[Max], str2[Max];int main(){ int T, k, i原创 2015-08-12 15:34:14 · 409 阅读 · 0 评论