Wireless password
Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 4022 accepted submission (s): 1196
Problem descriptionliyuan lives in a old apartment. one day, he suddenly found that there was a wireless network in the building. liyuan did not 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 that the password has ded at least K words of the magic word set (the K words in the password possibly overlapping ).
For instance, say that you know that the password is 3 characters long, And the magic word set has des 'She' and 'He'. Then the possible password is only 'she '.
Liyuan wants to know whether the information is enough to reduce the number of possible passwords. To answer this, please help him write a program that determines the number of possible passwords.
Inputthere will be several data sets. each data set will 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 has ded at least K words of the magic set. this is followed by M lines, each containing a word of the magic set, each word consists of between 1 and 10 lowercase letters 'a'-'Z '. end of input will be marked by a line with n = 0 m = 0 k = 0, which shoshould not be processed.
Outputfor each test case, please output the number of possible passwords mod 20090717.
Sample Input
10 2 2hello world 4 1 1icpc 10 0 00 0 0
Sample output
2114195065
Source2009 multi-university training contest 1-host by tju
Recommendgaojie | we have carefully selected several similar problems for you: 2819 2824 2817 2823 question: Someone is going to crack wifipassword. Now he knows that password is composed of lowercase letters. And the password length is n (1 <=n <= 25 ). And M (0 <= m <= 10) Possible strings in the password (MAGIC ). The length of each string cannot exceed 10. Now he knows that the M string in password must contain at least K. It can be overwritten. Ask you how many types of passwords you may have. Idea: because it is a topic dedicated to searching for the active mobility rules of the AC itself. So I thought about it directly on the AC's own mobile specifications. The difficulty of this question is to determine how many magic appears. Considering that M is smaller than limit. Therefore, the pressure is strong. Finally, you can obtain the status that meets the conditions. For details, see the code:
#include<algorithm>#include<iostream>#include<string.h>#include<sstream>#include<stdio.h>#include<math.h>#include<vector>#include<string>#include<queue>#include<set>#include<map>using namespace std;const int INF=0x3f3f3f3f;const double eps=1e-8;const double PI=acos(-1.0);const int mod=20090717;const int md=150;const int ssz=26;const int maxn=30;int ch[md][ssz],val[md],f[md],last[md];int sz,dp[maxn][md][1<<11],one[1<<11],bi[11];int idx(char c) { return c-'a'; }void init(){ sz=1; val[0]=0; memset(ch[0],0,sizeof ch[0]);}void Insert(char *s,int v){ int u=0,n=strlen(s); for(int i=0; i<n; i++) { int c=idx(s[i]); if(!ch[u][c]) { memset(ch[sz],0,sizeof ch[sz]); val[sz]=0; ch[u][c]=sz++; } u=ch[u][c]; } val[u]=v;}void getf(){ queue<int> q; int u,v,c,r; f[0]=0; for(c=0;c<ssz;c++) { u=ch[0][c]; if(u) { f[u]=0; q.push(u); last[u]=0; } } while(!q.empty()) { r=q.front(); q.pop(); val[r]|=val[f[r]]; for(c=0;c<ssz;c++) { u=ch[r][c]; if(!u) { ch[r][c]=ch[f[r]][c]; continue; } q.push(u); v=f[r]; while(v&&!ch[v][c]) v=f[v]; f[u]=ch[v][c]; } }}void solve(int n,int k,int ms){ int i,j,s,c,v,ns,ans; getf(); for(i=0;i<=n;i++) for(j=0;j<sz;j++) for(s=0;s<ms;s++) dp[i][j][s]=0; dp[0][0][0]=1; for(i=0;i<n;i++) for(j=0;j<sz;j++) for(s=0;s<ms;s++) { if(!dp[i][j][s]) continue; for(c=0;c<ssz;c++) { v=ch[j][c],ns=s|val[v]; dp[i+1][v][ns]=(dp[i+1][v][ns]+dp[i][j][s])%mod; } } ans=0; for(s=0;s<ms;s++) { if(one[s]<k) continue; for(i=0;i<sz;i++) ans=(ans+dp[n][i][s])%mod; } printf("%d\n",ans);}int getone(int x){ int c=0; while(x) { c+=x&1; x>>=1; } return c;}int main(){ int i,n,m,k; char magic[20]; bi[0]=1; for(i=1;i<11;i++) bi[i]=bi[i-1]<<1; for(i=0;i<bi[10];i++) one[i]=getone(i); while(scanf("%d%d%d",&n,&m,&k),n||m||k) { init(); for(i=0;i<m;i++) { scanf("%s",magic); Insert(magic,bi[i]); } solve(n,k,bi[m]); } return 0;}