zoukankan      html  css  js  c++  java
  • csuoj Nearest Sequence

    Description

            Do you remember the "Nearest Numbers"? Now here comes its brother:"Nearest Sequence".Given three sequences of char,tell me the length of the longest common subsequence of the three sequences.

    Input

            There are several test cases.For each test case,the first line gives you the first sequence,the second line gives you the second one and the third line gives you the third one.(the max length of each sequence is 100)

    Output

     

            For each test case,print only one integer :the length of the longest common subsequence of the three sequences.

    Sample Input

    abcd
    abdc
    dbca
    abcd
    cabd
    tsc

    Sample Output

    2
    1

    代码:

    #include<iostream>
    #include<string>
    using namespace std;
    string a,b,c;
    
    int dp[101][101][101];
    int main(){
        while(cin >> a >> b >> c){
            int x,y,z;
            x = a.size();
            y = b.size();
            z = c.size();
    //        cout << x << " " << y << " " << z << endl;
            dp[0][0][0] = 0;
            for(int i = 0;i <= x;i++){
                for(int j = 0;j <= y;j++)
                    dp[i][j][0] = 0;
            }
            for(int i = 0;i <= x;i++){
                for(int k = 0;k <= z;k++)
                    dp[i][0][k] = 0;
            }
            for(int j = 0;j <= y;j++){
                for(int k = 0;k <= z;k++)
                    dp[0][j][k] = 0;
            }
            for(int i = 1;i <= x;i++){
                for(int j = 1;j <= y;j++){
                    for(int k = 1;k <= z;k++){
    //                    cout << a[i - 1] << " " << b[j + 1] << " " << c[k + 1] << endl;
                        if(a[i - 1] == b[j - 1] && a[i - 1] == c[k - 1])
                            dp[i][j][k] = dp[i - 1][j - 1][k - 1] + 1;
                        else{
                            dp[i][j][k] = max(max(dp[i - 1][j][k],dp[i][j - 1][k]),max(dp[i - 1][j][k],dp[i][j][k - 1]));
                        }
    //                    cout << i << " " << j << " " << k << " " << dp[i][j][k] << endl;
                    }
                }
            }
            cout << dp[x][y][z] <<endl;
        }
        return 0;
    }
  • 相关阅读:
    JBPM工作流(四)——管理流程定义
    JBPM工作流(三)——ProcessEngine与Service API
    JBPM工作流(二)——数据库表说明
    JBPM工作流(一)——实现一个简单的工作流例子
    jbpm与spring hibernate struts整合
    SpringMVC12拦截器
    SpringMVC11文件上传
    阅读代码的方法
    关于linux系统的资料
    关于图灵机的介绍(相见恨晚,太赞了)
  • 原文地址:https://www.cnblogs.com/tracy520/p/6974477.html
Copyright © 2011-2022 走看看