#P2922. [USACO08DEC] Secret Message G
[USACO08DEC] Secret Message G
题目描述
Bessie is leading the cows in an attempt to escape! To do this, the cows are sending secret binary messages to each other.
Ever the clever counterspy, Farmer John has intercepted the first () bits of each of () of these secret binary messages.
He has compiled a list of () partial codewords that he thinks the cows are using. Sadly, he only knows the first () bits of codeword .
For each codeword , he wants to know how many of the intercepted messages match that codeword (i.e., for codeword , how many times does a message and the codeword have the same initial bits). Your job is to compute this number.
The total number of bits in the input (i.e., the sum of the and the ) will not exceed .
贝茜正在领导奶牛们逃跑.为了联络,奶牛们互相发送秘密信息.
信息是二进制的,共有 ()条,反间谍能力很强的约翰已经部分拦截了这些信息,知道了第 条二进制信息的前 ()位,他同时知道,奶牛使用 ()条暗号.但是,他仅仅知道第 条暗号的前 ()位。
对于每条暗号 ,他想知道有多少截得的信息能够和它匹配。也就是说,有多少信息和这条暗号有着相同的前缀。当然,这个前缀长度必须等于暗号和那条信息长度的较小者。
在输入文件中,位的总数(即 )不会超过 。
输入格式
Line : Two integers: and .
Lines : Line describes intercepted code with an integer followed by space-separated 0
's and 1
's.
Lines : Line describes codeword with an integer followed by space-separated 0
's and 1
's.
输出格式
Lines : Line : The number of messages that the -th codeword could match.
4 5
3 0 1 0
1 1
3 1 0 0
3 1 1 0
1 0
1 1
2 0 1
5 0 1 0 0 1
2 1 1
1
3
1
1
2
提示
Four messages; five codewords.
The intercepted messages start with 010, 1, 100, and 110.
The possible codewords start with 0, 1, 01, 01001, and 11.
0 matches only 010: 1 match
1 matches 1, 100, and 110: 3 matches
01 matches only 010: 1 match
01001 matches 010: 1 match
11 matches 1 and 110: 2 matches