I've never t^t it before. When you brush your teeth in the morning, you accidentally want to make mistakes.
To all the words of the AC automaton, and then run on the automaton DP, DP (I, j) represents the number of schemes that match the J-node on the automaton, and then enumerates the a~z to transfer.
--------------------------------------------------------------------------
#include <bits/stdc++.h>using namespace std;#define IDX (c) ((c)-' A ')const int MAXN = 109;const int MAXM =;const int N = +;const int MOD = 10007;struct Node {Node *ch[26], *fail;int id;bool F;} POOL[MAXN * MAXM], *pt = pool, *root = pt++; int CNT = 0, c = 0, p = 1, tot = 1;int N, m, DP[2][MAXN * MAXM];Char S[MAXN];inline node* NewNode () {pt->fail = root;pt->f = false;pt->id = cnt++;return pt++;}void Insert (char* c, int len) {node* t = root;For (; len--; C + +) {if (!t->ch[idx (*c)]) T->ch[idx (*c)] = NewNode ();t = t->ch[idx (*c)];}t->f = true;}queue<node*> Q;void BFS () {for (int i = 0; i < N; i++)if (Root->ch[i]) Q.push (Root->ch[i]);While (! Q.empty ()) {node* t = Q.front (); Q.pop ();for (int i = 0; i < N; i++) if (T->ch[i]) {node* o = t->fail;While (o! = root &&!o->ch[i]) o = o->fail;T->ch[i]->fail = (O->ch[i]? O->ch[i]: root);if (t->ch[i]->fail->f) t->ch[i]->f = true;Q.push (T->ch[i]);}}}void DFS (node* t) {//if (t->f | |!dp[p][t->id]) return; it ' s wrongif (t->f) return;for (int i = 0; i < N; i++) if (T->ch[i]) {DFS (T->ch[i]);Dp[c][t->ch[i]->id] + = dp[p][t->id];if (Dp[c][t->ch[i]->id] >= MoD) dp[c][t->ch[i]->id]-= mod;} else {node* o = t->fail;While (o! = root &&!o->ch[i]) o = o->fail;int id = (O->ch[i]? o->ch[i]->id:0);Dp[c][id] + = dp[p][t->id];if (Dp[c][id] >= MoD) dp[c][id]-= mod;}}void Dfs (node* t) {if (!t->f) {tot-= dp[c][t->id];if (Tot < 0) tot + = MOD;}for (int i = 0; i < N; i++)if (T->ch[i]) DFS (t->ch[i]);} int main () {root = NewNode (); root->fail = root;scanf ("%d%d", &n, &m);for (int i = 0; i < n; i++) {scanf ("%s", s);Insert (S, strlen (s));}BFS ();memset (DP, 0, sizeof DP);dp[c][0] = 1;for (int i = 0; i < m; i++) {(tot *=)%= MOD;Swap (c, p);memset (Dp[c], 0, sizeof dp[c]);DFS (root);}Dfs (root);printf ("%d\n", tot);return 0;}
--------------------------------------------------------------------------
1030: [JSOI2007] Text generator Time Limit:1 Sec Memory Limit:162 MB
Submit:2679 Solved:1107
[Submit] [Status] [Discuss] Description
Jsoi to the players zyx a task, the production of a "text generator" computer software: The user of the software is some low-young people, they are now using the GW Text Generator V6 version. The software can generate some random articles----always generate a fixed length and completely random article--that is, every byte in the generated article is completely random. If an article contains at least one word that the user understands, then we say this article is readable (we call the article A contains the word B when and only if the word b is a substring of article a). But even by this standard, the V6 version of the GW text generator that the user is using now is almost completely unreadable. ZYX need to indicate the number of readable text in all the text generated by the GW text Generator V6 so that the V7 update can be successfully obtained. Can you help him?
Input
The first line of the input file contains two positive integers, the total number of words that the user understands (<=), and the GW text generator v6 The resulting text fixed length m; The following n lines, each containing a word that the user understands. All words and text will not be longer than 100 and may contain only capital letters a. Z.
Output
An integer that represents the total number of possible articles. You only need to know the value of the result modulus 10007.
Sample Input 2 2
A
BSample Output -HINT
Source
Bzoj 1030: [JSOI2007] Text Generator (AC automaton + DP)