标签:
#include <iostream> #include <fstream> #include <string> #include <cstring> using namespace std; const int MAX = 1111; int dp[MAX][MAX]; int f(int x, int y) { if(x > y) return x; return y; } int main() { //fstream cin("aaa.txt"); string a, b; while(cin >> a >> b) { memset(dp, 0, sizeof(dp)); for(int i = 1; i <= a.size(); i++) for(int j = 1; j <= b.size(); j++) { if(a[i - 1] == b[j - 1]) dp[i][j] = dp[i - 1][j - 1] + 1; else dp[i][j] = f(dp[i - 1][j], dp[i][j-1]); } cout << dp[a.size()][b.size()] << endl; a = ""; b = ""; } return 0; }
标签:
原文地址:http://www.cnblogs.com/lyf-acm/p/5434106.html