贪心的预处理母本串从i到j的最大单词数
然后dp[i][j] 表示从前i个切了k次最优解
转移显然
#include<cstdio>
#include<algorithm>
#include<cstring>
const int maxn = 507;
char a[maxn];
char s[maxn],t[maxn];
int dp[maxn][55];
int n,k,q;
int num[maxn][maxn];
void get_tmp(char * p) {
int len = strlen(p + 1);
for(int i = 1;i <=n ;++i ) {
if(s[i] == a[i])
for(int j = 2;j <= len;++ j) {
if(s[i + j - 1] != a[j]) break;
if(j == len) num[i][j] ++;
}
}
}
int main () {
scanf("%d%d", &n,&k);
int tmp = 0;
for(int len , i = 1;i <= n; ++i) {
scanf("%s",a + 1); len = strlen(a + 1);
for(int j = 1;j <= len;++ j)
tmp ++, s[tmp] = a[j];
}
n = strlen(s + 1)
scanf("%d", &q);
for(int i = 1;i <= q;++ i) {
scanf("%s",t+1);
get_count(t);
}
}
原文:https://www.cnblogs.com/sssy/p/8783393.html