题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4681 题意: 给你a,b,c三个串,构造一个d串使得d是a,b的子序列,并且c是d的连续子串.求d最大的长度. 题解: 枚举a,b串开始匹配c的位置,(结束的位置可以贪心出来),然后前后都用最长公共子序列来跑就可以了. O(n^2)预处理,O(n^2)枚举. #pragma comment(linker, "/STACK:102400000,102400000") #include<…
Palindrome DescriptionA palindrome is a symmetrical string, that is, a string read identically from left to right as well as from right to left. You are to write a program which, given a string, determines the minimal number of characters to be inser…
Description A palindrome is a symmetrical string, that is, a string read identically from left to right as well as from right to left. You are to write a program which, given a string, determines the minimal number of characters to be inserted into t…
Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 48526   Accepted: 16674 Description A palindrome is a symmetrical string, that is, a string read identically from left to right as well as from right to left. You are to write a program whi…
Palindrome [题目链接]Palindrome [题目类型]最长公共子序列 &题解: 你做的操作只能是插入字符,但是你要使最后palindrome,插入了之后就相当于抵消了,所以就和在这个串中删除最少的字符,使得它回文是一样的. 那么我们可以把这个串reverse,之后的串称为s2,找s2和s的最长公共子序列就好了,因为有了LCS,接着把其他的都删掉,就是一个回文串了,因为正着读和倒着读都一样 还有POJ居然能跑5000^2 我的923MS就跑完了,还是很快的嘛,当然这题还可以滚动数组,…
Palindrome Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 56273   Accepted: 19455 Description A palindrome is a symmetrical string, that is, a string read identically from left to right as well as from right to left. You are to write a…
Common Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 39661    Accepted Submission(s): 18228 Problem Description A subsequence of a given sequence is the given sequence with some el…
题目描述:给出两个字符串,求两个字符串的公共子序列(不是公共子串,不要求连续,但要符合在原字符串中的顺序) in: abcfbc abfcab programming contest abcd mnp out: 4 2 0 状态转移方程: 如果s1[i]==s2[j] 则 c[i][j]=c[i-1][j-1]+1 如果s1[i]!=s2[j] 则 c[i][j]=max(c[i-1][j],c[i][j-1]) #include <iostream> #include <cstring…
#include <cstdio> #include <cstring> using namespace std; ; #define max(a,b) a>b?a:b char a[N] , b[N]; int dp[N][N]; int main() { , b+) != EOF){ ); ); ; i<=l1 ; i++) ; j<=l2 ; j++){ ][j-]+; ][j] , dp[i][j-]); } printf("%d\n"…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1513 解题报告:给定一个长度为n的字符串,在这个字符串中插入最少的字符使得这个字符串成为回文串,求这个最少的个数是多少? 一开始以为只是一个普通的DP题,但是按照我的想法敲出来之后怎么样都W了,无奈搜了解题报告,得知其实这个就是一个最长公共子序列问题,就是求这个字符串跟它的逆序的 字符串的最长公共子序列.因为杭电的题内存都要求在32M内存以内,所以很开心的敲出来才发现10^6的数组都开不了,所以只好…