标签:
题目:http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11313
1 #include<cstdio> 2 #include<string.h> 3 #include<algorithm> 4 using namespace std; 5 const int maxn=200+10; 6 int a[maxn],b[maxn]; 7 int dp[maxn][maxn]={0}; 8 9 int main() 10 { 11 int n,m; 12 while(scanf("%d",&n)!=EOF && n) 13 { 14 for (int i=1;i<=n;i++) 15 scanf("%d",&a[i]); 16 for (int i=1;i<=n;i++) 17 scanf("%d",&b[i]); 18 for (int i=1;i<=n;i++) 19 { 20 for (int j=1;j<=n;j++) 21 { 22 if (a[i]==b[j]) 23 dp[i][j]=dp[i-1][j-1]+1; 24 else 25 dp[i][j]=max(dp[i-1][j],dp[i][j-1]); 26 } 27 } 28 printf("%d\n",dp[n][n]); 29 } 30 return 0; 31 }
标签:
原文地址:http://www.cnblogs.com/caterpillarofharvard/p/4244930.html