题目:https://www.luogu.com.cn/problem/P1026
我的代码:
#include<bits/stdc++.h>
using namespace std;
int p,k,s,f[201][201],w[201][201];
char a[201],wo[11][201],te[21];
bool yes(int x,int e)
{
for(int q=1;q<=s;q++)
{
char *p=strstr(&a[x],wo[q]);
if(p!=NULL && p-&a[x]==0 && strlen(wo[q])<=e-x+1)
return true;
}
return false;
}
int main()
{
scanf("%d%d",&p,&k);
int g=p;
getchar();
while(p--)
{
gets(te);
strcat(&a[1],te);
}
scanf("%d",&s);
getchar();
for(int i=1;i<=s;i++)
gets(wo[i]);
for(int j=20*g;j>=1;j--)
for(int i=j;i>=1;i--)
{
if(yes(i,j))
w[i][j]=w[i+1][j]+1;
else
w[i][j]=w[i+1][j];
}
for(int i=1;i<=k;i++)
f[i][i]=f[i-1][i-1]+w[i][i];
for(int i=1;i<=20*g;i++)
f[i][1]=w[1][i];
for(int i=1;i<=g*20;i++)
for(int j=2;j<=k && j<i;j++)
for(int r=j;r<i;r++)
f[i][j]=max(f[i][j],f[r][j-1]+w[r+1][i]);
cout<<f[20*g][k];
return 0;
}
70分,#1#2#3WA
#1的输入:
2 2
thisisappleisthisthe
oopbooktheisurrtoywe
4
is
of
the
book
#1的输出:
8
我也输出了8,为啥错了呢?