/** * Common Subsequence (PKU 1458) * by Kenji Inoue, 2006-12-23 **/ #include using namespace std; int t[500][500]; // table int main() { string a, b; while (cin >> a >> b) { // cout << "[" << a << "] [" << b << "]" << endl; memset(t, 0, sizeof(t)); for (int y=1; y<=a.size(); y++) { for (int x=1; x<=b.size(); x++) { int v = t[y-1][x-1] + (a[y-1] == b[x-1]); if (t[y-1][x] > v) { v = t[y-1][x]; } if (t[y][x-1] > v) { v = t[y][x-1]; } t[y][x] = v; } } cout << t[a.size()][b.size()] << endl; } return 0; }