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

Input

The first line of input contains a number T, indicating the number of test cases. (T≤30) For each test case, the first line contains a string s, which is the string the God has. The following line contains a number n, the number of people’s names. Then n lines follow, each with a string indicating the names. There will be no more than 10 names in each test case, the length of string s will not exceed 100,000, and the length of each name will not exceed 100,000. All the strings contains lowercase letters from a to z only.

Output

For each case, output Case #i: first. (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
2
abc
3
aa
bb
cc
aabbc
3
abc
aa
bb
Case #1: 0
Case #2: 2

Source

The 11th UESTC Programming Contest Final
 
解题报告:
先扫出每个名字要多少个字符,之后暴力枚举拼的方式并更新ans
 
#include <iostream>
#include <cstring>
#include <algorithm> using namespace std; int letter[+];
int cost[+][+];
int ans;
char buffer[ + ]; int main(int argc , char * argv[])
{
int Case,T=;
scanf("%d%*c",&Case);
while(Case--)
{
memset(letter,,sizeof(letter));
memset(cost,,sizeof(cost));
int len,n;
gets(buffer);len = strlen(buffer);
for(int i = ; i < len ; ++ i )
letter[buffer[i]-'a']++;
scanf("%d%*c",&n);
for(int i = ; i < n ; ++ i)
{
gets(buffer);len = strlen(buffer);
for(int j = ; j < len ; ++ j )
cost[i][buffer[j]-'a']++;
}
int allcost[ + ];
ans = ;
for(int i = ; i < (<<n) ; ++ i)
{
memset(allcost,,sizeof(allcost));
int newans = ;
for(int j = ; j < n ; ++ j)
if ( ( i >> j ) & )
{
newans++;
for(int k = ; k < ; ++ k)
allcost[k] += cost[j][k];
}
int flag = ;
for(int j = ; j < ; ++ j)
if (allcost[j] > letter[j])
{
flag = ;
break;
}
if (flag)
ans = max(ans,newans);
}
printf("Case #%d: %d\n",T++,ans);
}
return ;
}

UESTC_Judgment Day CDOJ 11的更多相关文章

  1. 地区sql

    /*Navicat MySQL Data Transfer Source Server : localhostSource Server Version : 50136Source Host : lo ...

  2. CDOJ 1324 卿学姐与公主(分块)

    CDOJ 1324 卿学姐与公主(分块) 传送门: UESTC Online Judgehttp://acm.uestc.edu.cn/#/problem/show/1324 某日,百无聊赖的卿学姐打 ...

  3. WinForm 天猫2013双11自动抢红包【源码下载】

    1. 正确获取红包流程 2. 软件介绍 2.1 效果图: 2.2 功能介绍 2.2.1 账号登录 页面开始时,会载入这个网站:https://login.taobao.com/member/login ...

  4. C++11特性——变量部分(using类型别名、constexpr常量表达式、auto类型推断、nullptr空指针等)

    #include <iostream> using namespace std; int main() { using cullptr = const unsigned long long ...

  5. CSS垂直居中的11种实现方式

    今天是邓呆呆球衣退役的日子,在这个颇具纪念意义的日子里我写下自己的第一篇博客,还望前辈们多多提携,多多指教! 接下来,就进入正文,来说说关于垂直居中的事.(以下这11种垂直居中的实现方式均为笔者在日常 ...

  6. C++ 11 多线程--线程管理

    说到多线程编程,那么就不得不提并行和并发,多线程是实现并发(并行)的一种手段.并行是指两个或多个独立的操作同时进行.注意这里是同时进行,区别于并发,在一个时间段内执行多个操作.在单核时代,多个线程是并 ...

  7. CSharpGL(11)用C#直接编写GLSL程序

    CSharpGL(11)用C#直接编写GLSL程序 +BIT祝威+悄悄在此留下版了个权的信息说: 2016-08-13 由于CSharpGL一直在更新,现在这个教程已经不适用最新的代码了.CSharp ...

  8. ABP(现代ASP.NET样板开发框架)系列之11、ABP领域层——仓储(Repositories)

    点这里进入ABP系列文章总目录 基于DDD的现代ASP.NET开发框架--ABP系列之11.ABP领域层——仓储(Repositories) ABP是“ASP.NET Boilerplate Proj ...

  9. C++11 shared_ptr 智能指针 的使用,避免内存泄露

    多线程程序经常会遇到在某个线程A创建了一个对象,这个对象需要在线程B使用, 在没有shared_ptr时,因为线程A,B结束时间不确定,即在A或B线程先释放这个对象都有可能造成另一个线程崩溃, 所以为 ...

随机推荐

  1. 【实用技术】DreamWeaver常用快捷键

    文件菜单 新建文档 Ctrl+N 打开一个HTML文件 Ctrl+O 或者将文件从[文件管理器]或[站点]窗口拖动到[文档]窗口中 在框架中打开 Ctrl+Shift+O 关闭 Ctrl+W 保存 C ...

  2. 反转int型数字

    如 321 反转 123 120 反转21 注意处理最后的零,以及负数情况 ,最后就是溢出情况了 /** * @param {number} x * @return {number} */ var r ...

  3. Android恢复出厂设置流程分析【Android源码解析十】

    最近看恢复出厂的一个问题,以前也查过这方面的流程,所以这里整理一些AP+framework层的流程: 在setting-->备份与重置--->恢复出厂设置--->重置手机---> ...

  4. 机房收费系统合作版(三)——UI思索

    案件追踪系统1.0暂告一段落.验收过程中.MR MI针对UI界面提出了很多自己的想法. 针对TGB项目的UI设计我也有我的感受: 1.不论大小项目.仅仅要一看界面准有70%到80%熟悉度. 2.一看这 ...

  5. java RMI入门指南

    感觉这篇文章不错,直接转了 RMI全称是Remote Method Invocation-远程方法调用,Java RMI在JDK1.1中实现的,其威力就体如今它强大的开发分布式网络应用的能力上,是纯J ...

  6. 阿里云部署Docker(5)----管理和公布您的镜像

    出到这节,我在百度搜索了一下"阿里云部署Docker",突然发现怎么会有人跟我写的一样呢?哦,原来是其它博客系统的爬虫来抓取,然后也不会写转载自什么什么的.所以,我最终明确为什么那 ...

  7. Oracle字符集查看

    Oracle字符集是一个字节数据的解释的符号集合,有大小之分,有相互的包容关系.ORACLE 支持国家语言的体系结构允许你使用本地化语言来存储,处理,检索数据.它使数据库工具,错误消息,排序次序,日期 ...

  8. Linux UGO和ACL权限管理

    自主访问控制(Discretionary Access Control, DAC)是指对象(比如程序.文件.进程)的拥有者可以任意修改或者授予此对象相应的权限.Linux的UGO(User, Grou ...

  9. iOS textfield限制长度,中文占2字符,英文占1字符

    之前遇到一种情况,限制textfield长度,并且要适配多语言,做到,例如中文占2字符,英文占1字符,还有考虑其他语言,网上找了很多方法,不太合适,最后结合网上的方案,修改出了还比较适用. 首先,增加 ...

  10. DotDensityRenderer

    关键之处在于获取每个点所代表的的值 这里使用geodatabase类库中idatastatistic接口进行统计字段,再将结果传递给esrisysytem.istatisticsResult进行. 需 ...