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…
填坑的时候又到啦,校赛因为不会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)\).我们尝试…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1423 思路分析:[问题定义]给定两个序列A[0, 1,..., m]和B[0, 1, ..., n],要求这两个序列的最长公共上升子序列: 该问题为动态规划问题,可以采用与求最长公共子序列与最长上升子序列相同的思想来思考求出动态规划方程; 定义状态dp[i][j] 为序列A的前 i 个数字与序列B 的最长公共上升子序列,且该最长公共上升子序列以序列B的第 j 个数字为最后一个数字: 则可以推导出动态…
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…
HDOJ 1423 Greatest Common Increasing Subsequence [DP][最长公共上升子序列] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 8768 Accepted Submission(s): 2831 Problem Description This is a problem from ZOJ 24…
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,…
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 increasing subsequence of a sequence A1, A2, ..., AM of len…
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1423 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=28195#problem/F Greatest Common Increasing Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total…
题目链接: 题目 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…