Wireless Password
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 4688 Accepted Submission (s): 1433
Problem Description
Liyuan lives in a old apartment. One day, he suddenly found that there is a wireless network in the building. Liyuan didn't know the password of the network, but he got some important information from his neighbor. He knew the password consists only of lowercase letters ' a '-' Z ', and he knew the length of the password. Furthermore, he got a magic word set, and his neighbor told him then the password included at least K words of the Magic W Ord set (the K words in the password possibly overlapping).
For instance, say so know that the password is 3 characters long, and the magic word set includes ' she ' and ' he '. Then the possible password was only ' she '.
Liyuan wants to know whether the information was enough to reduce the number of possible passwords. To answer the him write a program that determines the number of possible passwords.
Input
There would be several data sets. Each data set would begin with a line with three integers n m k-N is the length of the password (1<=n<=25), M-is the Number of the words in the magic Word set (0<=m<=10), and the number k denotes that the password included at least K Words of the magic set. This was followed by M lines, each containing a word of the magic set, each word consists of between 1 and lowercase let Ters ' A '-' Z '. End of input would be marked by a line with n=0 m=0 k=0, which should not being processed.
Output
For each test case, please output the number of possible passwords MOD 20090717.
Sample Input
2 2 Hello World 4 1 1 icpc 10 0 0 0 0 0
Sample Output
2 1 14195065
Source
Multi-university Training Contest 1-host by Tju
Recommend
Gaojie | We have carefully selected several similar problems for you:2819 2824 2817 2823 2822
Statistic | Submit | Discuss | Note
Dp[i][j][k] represents the number of scenarios at node K, length I, State j
/************************************************************************* > File Name:hdu2825.cpp > Auth Or:alex > Mail: [email protected] > Created time:2015 March 07 Saturday 10:40 25 seconds ******************************** ****************************************/#include <map>#include <set>#include <queue>#include <stack>#include <vector>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>using namespace STD;Const DoublePI =ACOs(-1);Const intINF =0x3f3f3f3f;Const DoubleEPS =1e-15;typedef Long LongLL;typedefPair <int,int> PLL;Const intMax_node = $;Const intChild_num = -;Const intMoD =20090717;intdp[ -][(1<<Ten) +Ten][max_node];Charbuf[ -];intnum[ -];structac_automation{intNext[max_node][child_num];intFail[max_node];intEnd[max_node];intRoot, L;intNewNode () { for(inti =0; i < Child_num; ++i) {Next[l][i] =-1; } end[l++] =0;returnL1; }voidInit () {L =0; root = NewNode (); }voidBuild_trie (CharBuf[],intID) {intnow = root;intLen =strlen(BUF); for(inti =0; i < Len; ++i) {if(Next[now][buf[i]-' A '] == -1) {Next[now][buf[i]-' A '] = NewNode (); } now = Next[now][buf[i]-' A ']; } End[now] |= (1<< ID); }voidBuild_ac () { Queue <int>Qu Fail[root] = root; for(inti =0; i < Child_num; ++i) {if(Next[root][i] = =-1) {Next[root][i] = root; }Else{Fail[next[root][i]] = root; Qu.push (Next[root][i]); } } while(!qu.empty ()) {intnow = Qu.front (); End[now] |= End[fail[now]; Qu.pop (); for(inti =0; i < Child_num; ++i) {if(Next[now][i] = =-1) {Next[now][i] = Next[fail[now]][i]; }Else{Fail[next[now][i]] = next[fail[now]][i]; Qu.push (Next[now][i]); } } } }voidSolveintNintMintLim) { for(inti =0; I <= N; ++i) { for(intK =0; K < (1<< m); ++K) { for(intj =0; J <= L; ++J) {Dp[i][k][j] =0; }}} dp[0][0][0] =1; for(inti =0; I < n; ++i) { for(intK =0; K < (1<< m); ++K) { for(intj =0; J < L; ++J) {if(!dp[i][k][j]) {Continue; } for(intL =0; L < Child_num; ++L) {intnow = Next[j][l]; Dp[i +1][k | end[now]][now] + = dp[i][k][j]; Dp[i +1][k | end[now]][now]%= mod; } } } }intAns =0; for(inti =0; i < L; ++i) { for(intj =0; J < (1<< m); ++J) {if(Num[j] >= Lim) {ans + = dp[n][j][i]; Ans%= MoD; } } }printf("%d\n", ans); }}ac;intMain () {intN, M, K; for(inti =0; I <=1024x768; ++i) {Num[i] =0; for(intj =0; J <= One; ++J) {if(I & (1<< j)) {++num[i]; } } } while(~scanf("%d%d%d", &n, &m, &k) && (n + M + k)) {ac.init (); for(inti =0; I < m; ++i) {scanf('%s ', buf); AC. Build_trie (buf, i); } AC. Build_ac (); Ac.solve (n, M, k); }return 0;}
hdu2825---Wireless Password (AC automaton + pressure DP)