Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
串长没给,所以用了vector动态设置长度……#include <iostream> #include <string> #include <vector> using namespace std; string s1, s2; int main() { ios::sync_with_stdio(false); cin.tie(NULL); while(cin>>s1>>s2) { vector<int> f[2]; f[0].resize(s2.length() + 1); f[1].resize(s2.length() + 1); int cur = 0; for(int i=0; i<s1.length(); ++i) { for(int j=0; j<s2.length(); ++j) { f[cur][j+1] = max(f[cur^1][j] + (s1[i] == s2[j]), max(f[cur^1][j+1], f[cur][j])); } cur ^= 1; } cout<<f[cur^1][s2.length()]<<"\n"; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator