1、题目类型:DP。

2、解题思路:等待进一步整理。

3、注意事项:等待进一步整理。

4、实现方法:

#include<iostream>
#include
<string>
using namespace std;

int W,L;
int f[310],len[610];
char ch[610][100];
string str;

void Solve()
{
int i,j;
f[
0]=1;
for(i=0;i<L;i++)
{
if(i>0)
f[i]
=f[i-1]+1;
for(j=0;j<W;j++)
{
if(len[j]<=i+1&&ch[j][len[j]-1]==str[i])
{
int pos1=i;
int pos2=len[j]-1;
while(pos1>=0&&pos2>=0)
{
if(ch[j][pos2]==str[pos1])
pos2
--;
pos1
--;
}
int l=0;
if(pos2<0)
{
if(pos1<0)
l
=i+1-len[j];
else
l
=i-pos1-len[j]+f[pos1];
f[i]
=f[i]>l?l:f[i];
}
}
}
}
cout
<<f[L-1]<<endl;
}

int main()
{
int i;
cin
>>W>>L;
cin
>>str;
for(i=0;i<W;i++)
{
cin
>>ch[i];
len[i]
=strlen(ch[i]);
}

Solve();

return 0;
}

 

相关文章: