程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> hdu 2825 Wireless Password(ac自動機&dp)

hdu 2825 Wireless Password(ac自動機&dp)

編輯:C++入門知識

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 Description Liyuan 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 included 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 includes '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.

Input There 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 included 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 should not be processed.
Output For each test case, please output the number of possible passwords MOD 20090717.
Sample Input
10 2 2
hello 
world 
4 1 1
icpc 
10 0 0
0 0 0

Sample Output
2
1
14195065

Source 2009 Multi-University Training Contest 1 - Host by TJU
Recommend gaojie | We have carefully selected several similar problems for you: 2819 2824 2817 2823 2822 題意: 某人要去破譯wifi密碼。現在他已經知道密碼全部由小寫字母組成。且密碼的長度n(1<=n<=25)。和m(0<=m<=10)個密碼中可能出現的串(magic)。每個串長度不超過10.現在他已經知道密碼中這m個串至少出現了k個。可以覆蓋出現。現在問你密碼可能有多少種。 思路: 由於是專門搜的ac自動機動規的題目。所以就直接往ac自動機動規上想了。這題的難點是確定出現magic中出現了多少個。考慮到m比較小。所以就直接壯壓了。最後才取滿足條件的狀態就行了。 詳細見代碼:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
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 q;
    int u,v,c,r;
    f[0]=0;
    for(c=0;c>=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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved