| ||||||||||
| 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 | |||||||||
很多人问,贴一个0ms精简18行代码。#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(void){
string s1, s2;
while(cin >> s1 >> s2){
vector<vector<int> > c(s1.size() + 1, vector<int> (s2.size() + 1, 0));
for(int i = 1; i <= s1.size(); ++i)
for(int j = 1; j <= s2.size(); ++j)
if(s1[i - 1] == s2[j - 1])
c[i][j] = c[i - 1][j - 1] + 1;
else
c[i][j] = max(c[i - 1][j], c[i][j - 1]);
cout << c[s1.size()][s2.size()] << endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator