填坑的时候又到啦,校赛因为不会LCIS所以吃了大亏,这里要补起来.LCIS就是在两个串里找最长上升子序列,相关的博客有很多,这里自己就不写那么多了. http://www.cnblogs.com/jackge/archive/2013/05/16/3081793.html http://www.cnblogs.com/gj-Acit/p/3236384.html 上面两个博客对于O(n^2)的做法讲解的比较详细,大家可以参考一下. 贴两记代码 HDU1423 #pragma warning(di…
题意 如标题. \(|s1|,|s2| \leq 500\) 分析 既然是dp问题的组合,那么考虑dp. 定义状态f(i,j)表示对第一个序列s1的前i个和第二个序列s2的前j个元素求最长上升公共子序列,并且s1的第i个元素和s2的第j个元素匹配的结果,显然,当且仅当s1[i]=s2[j]时,f(i,j)有意义. 转移方程为: \[f(i,j)=\max\{f(i',j')|i'<i,j'<j,s2[j']<s1[i]\}+1\] 这个朴素做法的时间复杂度为\(O(n^4)\).我们尝试…
LIS和LCS的结合. 容易写出方程,复杂度是nm2,但我们可以去掉一层没有必要的枚举,用一个变量val记录前一阶段的最优解,这样优化成nm. 1<=k<j,j增加1,k的上界也增加1,就可以考虑用变量优化去掉一层循环. 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 const int maxn=505; 6 int n,m,T,an…
Problem Description This is a problem from ZOJ 2432.To make it easyer,you just need output the length of the subsequence.   Input Each sequence is described with M - its length (1 <= M <= 500) and M integer numbers Ai (-2^31 <= Ai < 2^31) - th…
Greatest Common Increasing Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3649    Accepted Submission(s): 1147 Problem Description This is a problem from ZOJ 2432.To make it easyer,…
题目链接: 题目 Greatest Common Increasing Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) 问题描述 This is a problem from ZOJ 2432.To make it easyer,you just need output the length of the subsequence. 输入 Each sequen…
题目地址:http://poj.org/problem?id=2127 Description You are given two sequences of integer numbers. Write a program to determine their common increasing subsequence of maximal possible length. Sequence S1 , S2 , . . . , SN of length N is called an increa…
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1423 Problem Description This is a problem from ZOJ 2432.To make it easyer,you just need output the length of the subsequence.   Input Each sequence is described with M - its length (1 <= M <= 500) and…
Greatest Common Increasing Subsequence 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1432 题目大意:给出两串数字,求他们的最长公共上升子序列(LCIS),并且打印出来. Sample Input 1 51 4 2 5 -124-12 1 2 4 Sample Output 21 4 分析:神奇就神奇在是LIS与LCS的组合 令dp[i][j]表示A串的前i个,与B串的前j…
HDU 1423 Greatest Common Increasing Subsequence(最长公共上升LCIS) http://acm.hdu.edu.cn/showproblem.php?pid=1423 题意: 给你两个数字组成的串a和b,要你求出它们的最长公共严格递增子序列的长度(LCIS). 分析: 首先我们令f[i][j]==x表示是a串的前i个字符与b串的前j个字符构成的且以b[j]结尾的LCIS长度. 当a[i]!=b[j]时:        f[i][j]=f[i-1][j…