Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
简单d【#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator