标签:blog http os io strong for ar 2014
// poj 1458 zoj 1733 最长公共子序列 DP
#include <iostream>
#include <string.h>
#define N 1005
using namespace std ;
char s1[N],s2[N]; int dp[N][N];
int max(int a,int b) { return a>b ? a : b ; }
void f(int n,int m)
{ int i,j;
for (i=0; i<n; i++) dp[i][0]=0;
for (j=0; j<m; j++) dp[0][j]=0;
for (i=1;i<=n; i++)
for (j=1;j<=m; j++)
if (s1[i-1]==s2[j-1]) dp[i][j]=dp[i-1][j-1]+1;
else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
}
int main()
{ int len1,len2;
while ( cin>>s1>>s2 )
{ len1=strlen(s1); len2=strlen(s2);
f(len1,len2);
cout << dp[len1][len2] << endl ; }
}
poj 1458 动态规划DP,布布扣,bubuko.com
标签:blog http os io strong for ar 2014
原文地址:http://www.cnblogs.com/2014acm/p/3917534.html