设为首页 加入收藏

TOP

HDU 4679 String
2014-11-23 19:01:45 来源: 作者: 【 】 浏览:4
Tags:HDU 4679 String

String
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 695 Accepted Submission(s): 254


Problem Description
Given 3 strings A, B, C, find the longest string D which satisfy the following rules:
a) D is the subsequence of A
b) D is the subsequence of B
c) C is the substring of D
Substring here means a consecutive subsequnce.
You need to output the length of D.


Input
The first line of the input contains an integer T(T = 20) which means the number of test cases.
For each test case, the first line only contains string A, the second line only contains string B, and the third only contains string C.
The length of each string will not exceed 1000, and string C should always be the subsequence of string A and string B.
All the letters in each string are in lowercase.


Output
For each test case, output Case #a: b. Here a means the number of case, and b means the length of D.


Sample Input
2
aaaaa
aaaa
aa
abcdef
acebdf
cf


Sample Output
Case #1: 4
Case #2: 3

Hint
For test one, D is "aaaa", and for test two, D is "acf".


Source
2013 Multi-University Training Contest 8


>Recommend
zhuyuanchen520


祭奠一下这个题

#include    
#include    
#include    
#include    
#define N 1100   
using namespace std;  
string s1,s2,s3,s4,s5;  
char temp[N];  
int num1[N][N],num2[N][N];  
struct num  
{  
    int sta,end;  
} a[N],b[N];  
int main()  
{  
    //freopen("data.in","r",stdin);   
    void get(int (*p)[N],string ch1,string ch2);  
    int t,tem=1;  
    scanf("%d",&t);  
    while(t--)  
    {  
        cin>>s1>>s2>>s3;  
        get(num1,s1,s2);  
        int l1 = s1.size();  
        for(int i=0; i<=l1-1; i++)  
        {  
            temp[l1-1-i] = s1[i];  
        }  
        temp[l1] = '\0';  
        s4 = temp;  
        int l2 = s2.size();  
        for(int i=0; i<=l2-1; i++)  
        {  
            temp[l2-1-i] = s2[i];  
        }  
        temp[l2] = '\0';  
        s5 = temp;  
        get(num2,s4,s5);  
        int l3 = s3.size(),Top1=0,Top2=0;  
        for(int i=0; i<=l1-1; i++)  
        {  
            if(s1[i]==s3[0])  
            {  
                int x = 0;  
                int sta = i;  
                int end = -1;  
                for(int j=i; j<=l1-1&&x<=l3-1; j++)  
                {  
                    if(s1[j]==s3[x])  
                    {  
                        x++;  
                    }  
                    if(x==l3)  
                    {  
                        end = j;  
                    }  
                }  
                if(end==-1)  
                {  
                    continue;  
                }  
                a[Top1].sta = sta;  
                a[Top1++].end = end;  
            }  
        }  
        for(int i=0; i<=l2-1; i++)  
        {  
            if(s2[i]==s3[0])  
            {  
                int x = 0;  
                int sta = i;  
                int end = -1;  
                for(int j=i; j<=l2-1&&x<=l3-1; j++)  
                {  
                    if(s2[j]==s3[x])  
                    {  
                        x++;  
                    }  
                    if(x==l3)  
                    {  
                        end = j;  
                    }  
                }  
                if(end==-1)  
                {  
                    continue;  
                }  
                b[Top2].sta = sta;  
                b[Top2++].end = end;  
            }  
        }  
        int res = l3,Max=0;  
        for(int i=0; i<=Top1-1; i++)  
        {  
            for(int j=0; j<=Top2-1; j++)  
            {  
                int x1 = a[i].sta;  
                int y1 = a[i].end;  
                int x2 = b[j].sta;  
                int y2 = b[j].end;  
                int k1 = 0;  
                if(x1>0&&x2>0)  
                {  
                    k1 = num1[x1-1][x2-1];  
                }  
                int k2 = 0;  
                if(y1 
 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇zoj 3165 (最小割,最大点权独立.. 下一篇poj1920 Towers of Hanoi

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Python 教程 - W3Sch (2025-12-26 12:00:51)
·Python基础教程,Pyt (2025-12-26 12:00:48)
·神仙级python入门教 (2025-12-26 12:00:46)
·“我用Java 8”已成 (2025-12-26 11:19:54)
·下载 IntelliJ IDEA (2025-12-26 11:19:52)