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

0 Ms 水果

Posted by 1468165899 at 2016-08-09 10:54:16 on Problem 2250
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
using namespace std;
char s1[102][31],s2[102][31];
int s,n,m,cnt;
int c[102][102];
int p[102][102];
int flag;
void LCS() {
    cnt=0;
    for(int i=1; i<n; i++) {
        for(int j=1; j<m; j++) {
            if(!strcmp(s1[i],s2[j])) {
                c[i][j]=c[i-1][j-1]+1;
                p[i][j]=1;
            } else {
                if(c[i-1][j]>c[i][j-1]) {
                    c[i][j]=c[i-1][j];
                    p[i][j]=2;
                } else {
                    c[i][j]=c[i][j-1];
                    p[i][j]=3;
                }
            }
        }
    }
}
void print(int i,int j) {
    if(p[i][j]==1) {
        print(i-1,j-1);
        printf("%s",s1[i]);
        if(flag) flag=0;
        else printf(" ");

    } else if(p[i][j]==2) {
        print(i-1,j);
    } else if(p[i][j]==3) {
        print(i,j-1);
    }
}
int main() {
    while(~scanf("%s",s1[1])) {
        n=1,m=0;
        while(scanf("%s",s1[++n]),s1[n][0]!='#') {}
        while(scanf("%s",s2[++m]),s2[m][0]!='#') {}
        memset(c,0,sizeof(c));
        LCS();
        flag=0;
        print(n-1,m-1);
    }
    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