Common Subsequence
HDU - 1159题意:裸的LCS
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
string a, b;
int dp[10010][10010];
int main(){
while(cin >> a >> b){
int n, m;
n=a.size();
m=b.size();
for(int i=0; i<=n; i++){
for(int j=0; j<=m; j++){
if(i==0||j==0) dp[i][j]=0;
else{
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]);
}
}
}
printf("%d\n", dp[n][m]);
}
return 0;
}