标签:
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
typedef long long LL;
const int maxn = 1000 + 100;
int dp[maxn][maxn];
int main(){
string str1,str2;
while(cin>>str1>>str2){
int m = str1.length();
int n = str2.length();
memset(dp,0,sizeof(dp));
for(int i = 0;i < m ; ++i){
for(int j = 0;j < n ; ++j){
if(str1[i] == str2[j] ){
dp[i+1][j+1] = dp[i][j] + 1;
}else {
dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1]);
}
}
}
cout<<dp[m][n]<<‘\n‘;
}
return 0;
}
[2016-03-28][POJ][1458][Common Subsequence]
标签:
原文地址:http://www.cnblogs.com/qhy285571052/p/4f2249a2006f88b8286272e9083f63b6.html