UESTC_Judgment Day CDOJ 11
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 |
Case #1: 0 |
Source
#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的更多相关文章
- 地区sql
/*Navicat MySQL Data Transfer Source Server : localhostSource Server Version : 50136Source Host : lo ...
- CDOJ 1324 卿学姐与公主(分块)
CDOJ 1324 卿学姐与公主(分块) 传送门: UESTC Online Judgehttp://acm.uestc.edu.cn/#/problem/show/1324 某日,百无聊赖的卿学姐打 ...
- WinForm 天猫2013双11自动抢红包【源码下载】
1. 正确获取红包流程 2. 软件介绍 2.1 效果图: 2.2 功能介绍 2.2.1 账号登录 页面开始时,会载入这个网站:https://login.taobao.com/member/login ...
- C++11特性——变量部分(using类型别名、constexpr常量表达式、auto类型推断、nullptr空指针等)
#include <iostream> using namespace std; int main() { using cullptr = const unsigned long long ...
- CSS垂直居中的11种实现方式
今天是邓呆呆球衣退役的日子,在这个颇具纪念意义的日子里我写下自己的第一篇博客,还望前辈们多多提携,多多指教! 接下来,就进入正文,来说说关于垂直居中的事.(以下这11种垂直居中的实现方式均为笔者在日常 ...
- C++ 11 多线程--线程管理
说到多线程编程,那么就不得不提并行和并发,多线程是实现并发(并行)的一种手段.并行是指两个或多个独立的操作同时进行.注意这里是同时进行,区别于并发,在一个时间段内执行多个操作.在单核时代,多个线程是并 ...
- CSharpGL(11)用C#直接编写GLSL程序
CSharpGL(11)用C#直接编写GLSL程序 +BIT祝威+悄悄在此留下版了个权的信息说: 2016-08-13 由于CSharpGL一直在更新,现在这个教程已经不适用最新的代码了.CSharp ...
- ABP(现代ASP.NET样板开发框架)系列之11、ABP领域层——仓储(Repositories)
点这里进入ABP系列文章总目录 基于DDD的现代ASP.NET开发框架--ABP系列之11.ABP领域层——仓储(Repositories) ABP是“ASP.NET Boilerplate Proj ...
- C++11 shared_ptr 智能指针 的使用,避免内存泄露
多线程程序经常会遇到在某个线程A创建了一个对象,这个对象需要在线程B使用, 在没有shared_ptr时,因为线程A,B结束时间不确定,即在A或B线程先释放这个对象都有可能造成另一个线程崩溃, 所以为 ...
随机推荐
- 使用 Strace 和 GDB 调试工具的乐趣
编写 UNIX® 系统程序充满乐趣,并且具有教育意义.使用 UNIX strace 工具和 GDB(GNU 项目调试工具),您可以真正地深入研究系统的功能,并了解组成这些功能的各种各样的程序.同时使用 ...
- 在wp中,使用NavigationService.Navigate导航页面出现错误
我们在WP项目中采用页面导航时候,经常会使用以下代码 NavigationService.Navigate(new Uri("/Page1.xaml",UriKind.Relati ...
- Uva11183-Teen Girl Squad(有向图最小生成树朱刘算法)
解析: 裸的有向图最小生成树 代码 #include<cstdio> #include<cstring> #include<string> #include< ...
- 《Algorithms 4th Edition》读书笔记——2.4 优先队列(priority queue)-Ⅲ
2.4.3 堆的定义 数据结构二叉堆能够很好地实现优先队列的基本操作.在二叉堆的数组中,每个元素都要保证大于等于另两个特定位置的元素.相应地,这些位置的元素又至少要大于等于数组中的两个元素,以此类推. ...
- Python Open Flash Chart (pyOFC2) — Home
Python Open Flash Chart (pyOFC2) - Home pyOFC2 Python Open Flash Chart 2
- iOS AFNetworking 详解
1. 很不错的介绍 http://m.blog.csdn.net/blog/jackljf/38736625
- java 集合专练
handsomecui的blog地址为:http://www.cnblogs.com/handsomecui/ 本人网站为:handsomecui.top 引言:本次主要练习单列集合:Collecti ...
- [转]Laravel 4之请求
Laravel 4之请求 http://dingjiannan.com/2013/laravel-request/ 获取请求数据 获取当前请求所包括的所有GET和POST数据 Route::get(' ...
- 解决WCF 调用方未由服务器进行身份验证或消息包含无效或过期的安全上下文令牌
错误描述: 1. WCF:调用方未由服务器进行身份验证 2. 无法处理消息.这很可能是因为操作“http://tempuri.org/ISCCLSvc/GetCarriersByWareHouse”不 ...
- RequireJs 深入理解
原文 http://www.tuicool.com/articles/jam2Anv RequireJs已经流行很久了,我们在项目中也打算使用它.它提供了以下功能: 声明不同js文件之间的依赖 可 ...