POJ-1458(LCS:最长公共子序列模板题)
Common Subsequence
POJ-1458
//最长公共子序列问题
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
string a,b;
int dp[1003][1003];
int main(){
while(cin>>a>>b){
int lena=a.length();
int lenb=b.length();
memset(dp,0,sizeof(dp));
for(int i=1;i<=lena;i++){
for(int j=1;j<=lenb;j++){
if(a[i-1]==b[j-1]){
dp[i][j]=dp[i-1][j-1]+1;
}else{
dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
}
}
}
cout<<dp[lena][lenb]<<endl;
}
return 0;
}
Either Excellent or Rusty