标签:style io ar color os sp for on 数据
2 asdf adfsd 123abc abc123abc
3 6
#include<stdio.h> # include<string.h> int s[1001][1001]; int max(int a,int b) { if(a>=b) return a; else return b; } int main() { int n,la,lb,i,j; scanf("%d",&n); while(n--) { char a[1001],b[1001]; scanf("%s%s",a,b); la=strlen(a); lb=strlen(b); for(i=0;i<=la;i++) s[0][i]=0; for(j=0;j<=lb;j++) s[j][0]=0; for(j=0;j<la;j++) for(i=0;i<lb;i++) { if(a[j]==b[i]) s[i+1][j+1]=s[i][j]+1; else s[i+1][j+1]=max(s[i][j+1],s[i+1][j]); } printf("%d\n",s[lb][la]); /*for(int i=0; i<la; i++) { old=0; for(int j=0; j<lb; j++) { tmp = dp[j]; //若s1[i]==s2[j], dp[i][j] = dp[i-1][j-1]+1 if(s1[i]==s2[j]) //否则,dp[i][j] = max(dp[i-1][j], dp[i][j-1]) dp[j] = old+1; //此处进行了空间优化,old 代表 dp[i-1][j-1] else //dp[j-1] 代表 dp[i][j-1], dp[j] 代表 dp[i-1][j] if(dp[j-1]>dp[j])dp[j]=dp[j-1];old = tmp; } } printf("%d\n", dp[lb-1]);*/ } return 0; }
标签:style io ar color os sp for on 数据
原文地址:http://blog.csdn.net/fwjynll/article/details/41681339