poj 2264(LCS)】的更多相关文章

Advanced Fruits Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2158   Accepted: 1066   Special Judge Description The company "21st Century Fruits" has specialized in creating new sorts of fruits by transferring genes from one fruit…
题目传送门 题意:两个字符串结合起来,公共的字符只输出一次 分析:LCS,记录每个字符的路径 代码: /* LCS(记录路径)模板题: 用递归打印路径:) */ #include <cstdio> #include <algorithm> #include <cmath> #include <cstring> #include <iostream> using namespace std; const int N = 1e2 + 10; cons…
转自:http://www.cppblog.com/varg-vikernes/archive/2010/09/27/127866.html 1)首先按照常规的方法求出最长公共子序列的长度也就是用O(MN)的那个动态规划,结果放在二维数组dp里dp[i][j] = { 字串a的1~i部分与字串b的1~j部分的最长公共子序列的长度 }2)求辅助数组last1[i][j] = { 到下标i为止,字符j在字串a中最后一次出现的下标 }last2[i][j] = { 到下标i为止,字符j在字串b中最后一…
compromise Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u   Description In a few months the European Currency Union will become a reality. However, to join the club, the Maastricht criteria must be fulfilled, and this is…
Secretary Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1655   Accepted: 671 Description The basic condition of success of a political party, it is the good Election Programme. PSOS know about it, so they entrust the top secretary Juli…
Advanced Fruits Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1944   Accepted: 967   Special Judge Description The company "21st Century Fruits" has specialized in creating new sorts of fruits by transferring genes from one fruit…
题目链接:http://poj.org/problem?id=1159 题意:给定一个长度为N的字符串.问你最少要添加多少个字符才能使它变成回文串. 思路:最少要添加的字符个数=原串长度-原串最长回文子串长度.对于求原串最长回文子串长度用的是DP的经典问题LCS最长公共子序列的做法. 设原串为S,原串的逆串为S‘,那么原串的最长回文子串长度=S和S'的最长公共子序列长度. 由于N的范围最大是5000,所以5000*5000的数组开不下,所以需要用到滚动数组来求.[关于原串求最长回文子串用的Man…
题目传送门 题意:输出两字符串的最长公共子序列长度 分析:LCS(Longest Common Subsequence)裸题.状态转移方程:dp[i+1][j+1] = dp[i][j] + 1; (s[i] == t[i])dp[i+1][j+1] = max (dp[i][j+1], dp[i+1][j]); (s[i] != t[i]) 代码: #include <cstdio> #include <cstring> #include <iostream> #in…
题目 以前做过的一道题, 今天又加了一种方法 整理了一下..... 题意:给出一个字符串,问要将这个字符串变成回文串要添加最少几个字符. 方法一: 将该字符串与其反转求一次LCS,然后所求就是n减去 最长公共子串的长度. 额,,这个思路还是不是很好想. LCS: #include<iostream> #include<cstring> #include<cstdio> using namespace std; +; char s1[maxn], s2[maxn]; ][…
POJ 2250 Compromise(LCS)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#problem/D 题目: Description In a few months the European Currency Union will become a reality. However, to join the club, the Maastricht criteria must be fulf…