#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
size_t cs(string const& a, string const& b) {
size_t table[256][256]={0};
for(size_t ia=1;ia<=a.length();++ia)
for(size_t ib=1;ib<=b.length();++ib)
table[ia][ib]=a[ia-1]==b[ib-1]?table[ia-1][ib-1]+1:max(table[ia-1][ib],table[ia][ib-1]);
return table[a.length()][b.length()];
}
int main() {
for(string a,b;cin>>a>>b;cout<<cs(a,b)<<endl);
return 0;
}
Saturday, 21 March 2009
POJ ( acm.pku.edu.cn ) 1458
经典DP,做过一次以后再做就觉得简单了。
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment