3942 - Remember the Word
思路:字典树+dp
dp[i]前i个字符,能由给的字串组成的方案数,那么dp[i] = sum(dp[i-k]);那么只要只要在字典树中查看是否有字串str[i-k+1,i]就行了;
1 #include<stdio.h> 2 #include<algorithm> 3 #include<stdlib.h> 4 #include<queue> 5 #include<iostream> 6 #include<string.h> 7 #include<math.h> 8 using namespace std; 9 typedef long long LL; 10 struct node 11 { 12 node *p[26]; 13 bool flag; 14 node() 15 { 16 memset(p,0,sizeof(p)); 17 flag = false; 18 } 19 }; 20 char str[300005]; 21 char ans[300]; 22 char bns[300]; 23 node *head; 24 void in(char *c,int l); 25 void ask(char *c,int k,int l); 26 LL dp[300005]; 27 const LL mod = 20071027; 28 void fr(node *q); 29 int main(void) 30 { 31 int i,j; 32 int __ca = 0; 33 while(scanf("%s",str)!=EOF) 34 { 35 int l = strlen(str); 36 int n; 37 scanf("%d",&n); 38 head = new node(); 39 while(n--) 40 { 41 scanf("%s",ans); 42 int k = strlen(ans); 43 in(ans,k); 44 } 45 memset(dp,0,sizeof(dp)); 46 dp[0] = 1; 47 for(i = 0; i < l; i++) 48 { 49 int x = max(0,i-100); 50 int v = 0; 51 for(j = i; j >= x; j--) 52 { 53 bns[v++] = str[j]; 54 } 55 bns[v] = '