Substring
Given a set of pattern strings, and a text, you have to find, if any of the pattern is a substring of the text. If any of the pattern string can be found in text, then print “yes”, otherwise “no” (without quotes).
But, unfortunately, that’s not what is asked here. J
The problem described above, requires a input file generator. The generator generates a text of length L, by choosing L characters randomly. Probability of choosing each character is given as priori, and independent of choosing others.
Now, given a set of patterns, calculate the probability of a valid program generating “no”.
Input
First line contains an integer T, the number of test cases. Each case starts with an integer K, the number of pattern strings. Next K lines each contain a pattern string, followed by an integer N, number of valid characters. Next N lines each contain a character and the probability of selecting that character, pi. Next an integer L, the length of the string generated. The generated text can consist of only the valid characters, given above.
There will be a blank line after each test case.
Output
For each test case, output the number of test case, and the probability of getting a “no”.
Constraints
· T
· ∑pi = 1
·
Sample input
2
1
a
2
a 0.5
b 0.5
2
2
ab
ab
2
a 0.2
b 0.8
2
Output for Sample Input
Case #1: 0.250000
Case #2: 0.840000
本题利用了AC自动机
首先,把模式串p推入AC自动机,然后dp[i][j]表示匹配到i点没成功,还剩j个字符未匹配的概率,dp
注意AC自动机上的dp(我之前忘了getFail()了,,,考挂自己弱)