For example, Z = < a, b, f, c > is a subsequence of X = < a, b, c, f, b, c > with index sequence < 1, 2, 4, 6 >. Given two sequences X and Y the problem is to find the length of the maximum-length common subsequence of X and Y. InputThe program input is from...
最长公共子序列求解问题。 1 #include 2 #include 3 const int maxn=1000; 4 char s1[maxn],s2[maxn]; 5 int c[maxn][maxn]; 6 int main() 7 { 8 while(scanf("%s%s&quo
#include<iostream> #include<cstdio> using namespace std; int maxLen[1000][1000]; int main() { string s1,s2; while(cin >> s1 >> s2) { int length1 = s1.length(); int length2 = s2.length(); for(int i = 0;i < length1; i++) maxLen[i][0] = 0; for(int i = 0;i ...
DP。。。 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; char a[305],b[305]; int f[305][305]; int main() { while(scanf("%s%s",a,b)!=EOF){ int alen=strlen(a); int blen=strlen(b); for(int i=1;i<=alen;i++) for(int j=1;j<=blen;j++...
题目链接经典DP问题。由于最初if(c[i][j]>=0) return c[i][j];一句中少写一个等于号造成TLE,查了好久啊……View Code 1 #include <stdio.h> 2 #include <string.h> 3 #define MAX(
最长公共子序列。状态转移方程见代码。 #include <iostream> #include <cstdio> #include <cstring> using namespace std; char s1[1005],s2[1005]; int dp[1005][1005]; int main() { while(scanf("%s",s1+1)!=EOF) { scanf("%s",s2+1); ...