1590: [Usaco2008 Dec]secret message secret information

Source: Internet
Author: User

1590: [Usaco2008 dec]secret message Secret message time limit:5 Sec Memory limit:32 MB
submit:209 solved:143
[Submit] [Status] [Discuss] Description Bessie was leading the cows to flee.    In order to contact, the cows send each other secret information. The information is binary, with a total of M (1≤m≤50000) bars. A strong anti-espionage John has partially intercepted this information, knowing the pre-bi (l bi≤10000) bit of the binary information of article I. He also knows that cows use N (1≤n≤50000) codes.    However, he is only aware of the former CJ (1≤cj≤10000) Bit of the code of Article J. For each password J, he wanted to know how much of the truncated information would match it. That is, how much information has the same prefix as this password.    Of course, the prefix length must be equal to the password and the smaller of the length of the message. In the input file, the total number of bits (that is, ∑bi+∑ci) does not exceed the 1th line of 500000.Input input n and M, followed by n lines to describe the secret information, followed by the M line to describe the password. Enter an integer for each line to indicate the length of the information or password, and then enter this information or password. All numbers are separated by a space. Output is a total of M rows, which outputs the number of matching information for each password. Sample Input4 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

INPUT DETAILS:

four messages; Five codewords.
The intercepted messages start with 010, 1, 110, and.
The possible codewords start with 0, 1, 01001, and 11.


Sample Output1
3
1
1
2

HINT

0 matches only 010:1 match 1 matches 1, and 110:3 matches-matches only 010:1 match 01001 matches 010:1 match 1 1 matches 1 and 110:2 matches

Source

Gold

Problem: A more interesting dictionary tree (trie tree) topic, you can do a good job of prefix comparison, if it is only in the first n sequence to find the number of M prefix, that is a template problem ... Just here obviously also need to consider in the rear m inside to find the first n prefix, then in fact, only need to store a value in the dictionary tree, that is, the information of the subtree, specifically a little unclear, see the program bar, writing is still clear ... (Pay attention to match half of the situation, it is a failure, oh, for this I wa once)
1 type2Point=^node;3Node=Record4 Tt,ex:longint;5NextArray[0..1] ofPoint ;6     End;7 var8 I,j,k,l,m,n:longint;9 Head:point;Ten s1:ansistring; One functionNewp:point; A          varP:point; -          begin -New (p);p ^.tt:=0;p ^.ex:=0; thep^.next[0]:=Nil;p ^.next[1]:=Nil; - exit (p); -          End; - procedureInsert (s1:ansistring); +           varI:longint;p:point; -           begin +p:=head; A                 fori:=1  toLength (S1) Do at                    begin -                         ifP^.next[ord (S1[i])- -]=Nil  Then -P^.next[ord (S1[i])- -]:=NEWP; -P:=p^.next[ord (S1[i])- -]; - Inc (P^.TT); -                    End; in Inc (P^.EX); -           End; to functionnum (s1:ansistring): Longint; +          varI,j,k,l:longint;p:point; -          begin thep:=head;j:=0; k:=0; l:=0; *                fori:=1  toLength (S1) Do $                   beginPanax Notoginseng                        ifP^.next[ord (S1[i])- -]=Nil  ThenBreak ; -P:=p^.next[ord (S1[i])- -]; thek:=k+J; +j:=P^.ex; Al:=i; the                   End; +               ifL<>i ThenNum:=k+jElsenum:=k+p^.tt; -          End; $ begin $ readln (n,m); -head:=NEWP; -       fori:=1  toN Do the          begin -Read (l); s1:="';Wuyi                forj:=1  toL Do the                   begin - read (k); WuS1:=S1+CHR ( -+k); -                   End; About Readln; $ Insert (S1); -          End; -       fori:=1  toM Do -          begin ARead (l); s1:="'; +                forj:=1  toL Do the                   begin - read (k); $S1:=S1+CHR ( -+k); the                   End; the Readln; the writeln (num (s1)); the          End; - Readln; in End.

1590: [Usaco2008 Dec]secret message secret information

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.