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

简单d【

Posted by bxdd at 2018-07-23 00:58:02 on Problem 3267
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int W,L;
int Dp[305];
char data[305];
char Voc[605][30];
int Len[605];
int main()
{
    scanf("%d%d",&W,&L);
    scanf("%s",data+1);
    data[0]=' ';
    for(int i=1;i<=W;i++){
        scanf("%s",Voc[i]+1);
        Len[i]=strlen(Voc[i]+1);
    }
    Dp[0]=0;
    for(int i=1;i<=L;i++){
        Dp[i]=Dp[i-1]+1;
        for(int j=1;j<=W;j++){
            if(Voc[j][Len[j]]==data[i]){
                int id1=i-1,id2=Len[j]-1;
                while(true){
                    if(id1==0||id2==0){
                        break;
                    }
                    if(data[id1]==Voc[j][id2]){
                        id1--;
                        id2--;
                    }
                    else{
                        id1--;
                    }

                }
                if(id2==0){
                    Dp[i]=min(Dp[i],Dp[id1]+i-id1-Len[j]);
                }
            }
        }
    }
    printf("%d",Dp[L]);
    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