Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

串长没给,所以用了vector动态设置长度……

Posted by yyii1111 at 2014-11-11 21:05:59 on Problem 1458
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator