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线程先释放这个对象都有可能造成另一个线程崩溃, 所以为 ...
随机推荐
- 去掉java反编译(JD-GUI)生成的源文件中注释
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.Fi ...
- 3Sum Smaller 解答
Question Given an array of n integers nums and a target, find the number of index triplets i, j, k w ...
- ajax的封装
ajax是前端工程中与后台进行数据交互的一门重要技术,通过在后台与服务器进行少量数据交换,AJAX 可以使网页实现异步更新.这意味着可以在不重新加载整个网页的情况下,对网页的某部分进行更新.jquer ...
- 泛泰A880S升级官方4.4.2 binx教程
之前为了尝鲜,直接官升4.4.2,红砖了.越南兄弟说官方没更新升级工具,所以导致升级到78%就停止了,他给的办法,我试也没成功.官方旧版本号又不能升级S0221118以上的版本号,新版的离线升级工具没 ...
- IOS自适应库---- Masonry的使用
Masonry是一个轻量级的布局框架,拥有自己的描述语法,采用更优雅的链式语法封装自动布局,简洁明了并具有高可读性,而且同时支持 iOS 和 Max OS X.Masonry是一个用代码写iOS或OS ...
- C#参数传递、引用类型、值类型等的理解
本博客不属于技术贴,主要是记录一些自己对不懂得地方的理解和学习的记录,请带着批判的眼光阅读~ 值类型存储在栈上,引用类型存储在堆上.栈是由高到低存储的,遵循先进后出的原则,是内存提前分配好的区域,内存 ...
- C#实现在线更新系统
先来看一下程序完成后长什么样. 这个是程序的组成部分. 主要功能是在InitializationUpdate这个类中完成的,From1主要起到调用的作用,所以重心还是在InitializationUp ...
- 求一无序数组中第n大的数字 - 快速选择算法
逛别人博客的时候,偶然看到这一算法题,顺便用C++实现了一下. 最朴素的解法就是先对数组进行排序,返回第n个数即可.. 下面代码中用的是快速选择算法(不晓得这名字对不对) #include <v ...
- 三大主流ETL工具选型
ETL(extract, transform and load)产品乍看起来似乎并不起眼,单就此项技术本身而言,几乎也没什么特别深奥之处,但是在实际项目中,却常常在这个环节耗费太多的人力,而在后续的维 ...
- [转载]Silverlight实用窍门系列:71.Silverlight的Style
本文版权归作者和博客园共有,欢迎转载,未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利. 原文链接:http://www.cnblogs.com/chengx ...