标签:style class blog c code java
/* * @author Panoss */ #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> #include<vector> #include<ctime> #include<stack> #include<queue> #include<list> using namespace std; #define DBG 1 #define fori(i,a,b) for(int i = (a); i < (b); i++) #define forie(i,a,b) for(int i = (a); i <= (b); i++) #define ford(i,a,b) for(int i = (a); i > (b); i--) #define forde(i,a,b) for(int i = (a); i >= (b); i--) #define forls(i,a,b,n) for(int i = (a); i != (b); i = n[i]) #define mset(a,v) memset(a, v, sizeof(a)) #define mcpy(a,b) memcpy(a, b, sizeof(a)) #define dout DBG && cerr << __LINE__ << " >>| " #define checkv(x) dout << #x"=" << (x) << " | "<<endl #define checka(array,a,b) if(DBG) { \ dout<<#array"[] | " << endl; forie(i,a,b) cerr <<"["<<i<<"]="<<array[i]<<" |"<<((i-(a)+1)%5?" ":"\n"); if(((b)-(a)+1)%5) cerr<<endl; } #define redata(T, x) T x; cin >> x #define MIN_LD -2147483648 #define MAX_LD 2147483647 #define MIN_LLD -9223372036854775808 #define MAX_LLD 9223372036854775807 #define MAX_INF 18446744073709551615 inline int reint() { int d; scanf("%d",&d); return d; } inline long relong() { long l; scanf("%ld",&l); return l; } inline char rechar() { scanf(" "); return getchar(); } inline double redouble() { double d; scanf("%lf", &d); return d; } inline string restring() { string s; cin>>s; return s; } int c[205][205]; /* c[i][j]表示从A1...i和B1...j的最长公共子序列长度为c[i][j] 状态转移方程为 c[i][j] = 0 i=0或j=0; c[i][j] = c[i-1][j-1] + 1 Ai = Bj c[i][j] = max(c[i-1][j],c[i][j-1]) i,j>0,Ai!=Bi */ char A[205], B[205]; int A_length, B_length; void DP() { mset(c,0); A_length = strlen(A); B_length = strlen(B); forde(i,A_length,1) //先全部后移一位 A[i] = A[i-1]; forde(i,B_length,1) B[i] = B[i-1]; forie(i,1,A_length) { forie(j,1,B_length) { if(A[i] == B[j]) { c[i][j] = c[i-1][j-1] + 1; } else { c[i][j] = max(c[i-1][j],c[i][j-1]); } } } } int main() { //freopen("data.txt","r",stdin); scanf("%s",A); scanf("%s",B); DP(); cout << c[A_length][B_length] << endl; return 0; }
标签:style class blog c code java
原文地址:http://www.cnblogs.com/Panoss/p/3741929.html