POJ 2127】的更多相关文章

题目地址: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…
由于noi OJ上没有Special Judge,所以我是没有在这上面AC的.但是在POJ上A了. 题意如标题. 解法:f[i][j]表示a串前i个和b串前j个且包含b[j]的最长公共上升子序列长度 首先,可用3重循环得到,k循环找到b串j之前的最大长度子序列的结尾字符b[k],得以更新现在f[i][j]的状态.然后,由于k循环的都在j之前,可发现k循环可略去,直接将满足上升的字符用临时变量存,每次j循环的都更新就好了. 具体上,最初f[i][j]=f[i-1][j],先继承好上一个状态,a[i…
#include <iostream> #define MAXN 501 using namespace std; int a[MAXN],b[MAXN],ans[MAXN]; int GCIS(int l1, int *a, int l2, int *b); int main() { //freopen("acm.acm","r",stdin); int l_1; int l_2; int i; int j; int ans_max; // cin&g…
这个题   用一维 为什么错了: 因为 用一维 dp 方程肯定也是一维:但是有没有想,第 i 个字符更新了 j 位置的最优结果,然后 k 字符又一次更新了  j 位置的最优值,然后  我的结果是  i 字符更新的结果: 但被覆盖了 所以错了:  不如用一个二维数组 表示  地 i 个字符放进去匹配另一个字符的 j 位置的最优值是由那个位置传递过来的: #include<iostream> #include<stdio.h> #include<algorithm> #in…
动态规划法: #include <iostream> #include <cstdio> #include <fstream> #include <algorithm> #include <cmath> #include <deque> #include <vector> #include <queue> #include <string> #include <cstring> #inc…
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…
Sample Input 5 1 4 2 5 -12 4 -12 1 2 4 Sample Output 2 1 4 题目:给你两个数字序列,求出这两个序列的最长公共上升子序列.输出最长的长度,并打表输出.可能存在多种正确答案,故此题是special judge! 分析:dp[i][j] : A[1...i]和B[1...j]的公共上升子序列中以B[j]为结尾的最长的长度.如果A[i] != B[j], 则dp[i][j]=d[i-1][j]; 也就是说当前这个A[i]是没效用的.如果A[i]…
\(Greatest Common Increasing Subsequence\) 大致题意:给出两个长度不一定相等的数列,求其中最长的公共的且单调递增的子序列(需要具体方案) \(solution:\) 这道题如果不看具体方案,且我们要求的子序列不存在相同的元素,那么我们可以用 \(cdq\) 分治来搞搞,首先我们记录第二个数列中的元素在第一个数列里出现的位置(假设不存在重复,没有的不管),然后我们的第二个数列的每一个元素就有两个权值了,这是我们只需要两个权值均单调递增即可(这是 $cdq…
CodeForces 429B  Working out 预处理出从四个顶点到某个位置的最大权值,再枚举相遇点,相遇的时候只有两种情况,取最优解即可. #include<iostream> #include<vector> #include<cmath> #include<map> #include<algorithm> #include<cstring> #include<cstdio> #include<cstd…
LICS:最长公共上升子序列: 一般令f[i][j]表示a串前i位,b串以j结尾的LICS长度.于是,答案为:max(1~m)(f[n][i]); 朴素做法:O(n^3) 相等时,从1~j-1枚举最大值. ;i<=n;i++) ;j<=m;j++) {][j]; else if(a[i]==b[j]) ;k<j;k++) ][k]; } 算法时间复杂度改进思路主要从优化第三层(k)复杂度入手. 升级做法: O(n^2logn) 利用树状数组记录f[i-1][1~j-1]最大值: 数组下表…