错题集:Censored!

Censored!(题目来源:Ural 1158)
【题目描述】已知一个由n(1<=n<=50)个字符组成的字符集及p(0<=p<=10)个不良单词(长度均不超过10),求长度为m(1<=m<=50)且不含不良单词的字符串的数目。
【输入(标准输入)】第一行为三个整数n,m,p。第二行为n个字符,表示字符集。下面p行,每行一个不良单词。
【输出(标准输出)】一个整数,表示长度为m且不含不良单词的字符串的数目

【样例输入】

3 3 3
QWE
QQ
WEE
Q

【样例输出】

7 

【算法标签】 Trie图

展开阅读全文

Censored!

06-15

The alphabet of Freeland consists of exactly N letters. Each sentence of Freeland language (also known as Freish) consists of exactly M letters without word breaks. So, there exist exactly N^M different Freish sentences.nnBut after recent election of Mr. Grass Jr. as Freeland president some words offending him were declared unprintable and all sentences containing at least one of them were forbidden. The sentence S contains a word W if W is a substring of S i.e. exists such k >= 1 that S[k] = W[1], S[k+1] = W[2], ..., S[k+len(W)-1] = W[len(W)], where k+len(W)-1 <= M and len(W) denotes length of W. Everyone who uses a forbidden sentence is to be put to jail for 10 years.nnFind out how many different sentences can be used now by freelanders without risk to be put to jail for using it.nnnInputnnThe first line of the input file contains three integer numbers: N - the number of letters in Freish alphabet, M - the length of all Freish sentences and P - the number of forbidden words (1 <= N <= 50, 1 <= M <= 50, 0 <= P <= 10).nnThe second line contains exactly N different characters - the letters of the Freish alphabet (all with ASCII code greater than 32).nnThe following P lines contain forbidden words, each not longer than min(M, 10) characters, all containing only letters of Freish alphabet.nnProcess to the end of file.nnnOutputnnOutput the only integer number - the number of different sentences freelanders can safely use.nnnSample Inputnn2 3 1nabnbbn3 2 0n012n3 3 3nQWEnQQnWEEnQn2 50 4nABnAAnABnBAnBBnnnSample Outputnn5n9n7n0n 问答

没有更多推荐了,返回首页