Uestc_judgment Day Cdoj 11

Source: Internet
Author: User

Today is the judgment Day. The world was ending and all man would pay for their guilt and sin. Now the Almighty God has a long string, and some people ' s name. He'll take some letters from the string and use them to spell out those people ' s name. What's the maximum number of the names that can being spelled, with each name being spelled at most once?

Input

The first line of input contains a numberT, indicating the number of test cases. (T≤ ) For each test case, the first line contains a strings, which is the string the God has. The following line contains a numberNThe number of people ' s names. ThenNLines follow, each with a string indicating the names. There'll be is no more thanTenNames in all test case, the length of stringswould not exceedAnd the length of each name would not exceed . All the strings contains lowercase letters a z from to only.

Output

For each case, output first Case #i: . (i is the number of the "test case" from 1 to T). Then output a single number, as the maximum number of the people whose name can be spelled.

Sample Input and output
Sample Input Sample Output
2abc3aabbccaabbc3abcaabb
Case #1:0Case #2:2
Sourcethe 11th UESTC Programming Contest FinalProblem Solving Report:first sweep out each name to how many characters, after the violent enumeration spell the way and update ans
#include <iostream>#include<cstring>#include<algorithm>using namespacestd;intletter[ -+5];intcost[Ten+3][ -+5];intans;Charbuffer[100000+ -];intMainintARGC,Char*argv[]) { intcase,t=1; scanf ("%d%*c",&Case );  while(case--) {memset (letter,0,sizeof(letter)); memset (Cost,0,sizeof(cost)); intLen,n; Gets (buffer); Len=strlen (buffer);  for(inti =0; i < Len; ++i) letter[buffer[i]-'a']++; scanf ("%d%*c",&N);  for(inti =0; I < n; ++i) {gets (buffer); Len=strlen (buffer);  for(intj =0; J < Len; ++j) Cost[i][buffer[j]-'a']++; }    intallcost[ -+5]; Ans=0;  for(inti =1; I < (1&LT;&LT;N); ++i) {memset (Allcost,0,sizeof(Allcost)); intNewans =0;  for(intj =0; J < N; ++j)if((i >> J) &1) {Newans++;  for(intK =0; K < -; ++k) Allcost[k]+=Cost[j][k]; }        intFlag =1;  for(intj =0; J < -; ++j)if(Allcost[j] >Letter[j]) {Flag=0;  Break; }        if(flag) ans=Max (Ans,newans); } printf ("Case #%d:%d\n", t++, ans); } return 0;}

Uestc_judgment Day Cdoj 11

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.