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
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[26+5];
int cost[10+3][26+5];
int ans;
char buffer[100000 + 50];

int main(int argc , char * argv[])
{
 int Case,T=1;
 scanf("%d%*c",&Case);
 while(Case--)
  {
      memset(letter,0,sizeof(letter));
      memset(cost,0,sizeof(cost));
      int len,n;
      gets(buffer);len = strlen(buffer);
      for(int i = 0 ; i < len ; ++ i )
       letter[buffer[i]-‘a‘]++;
      scanf("%d%*c",&n);
      for(int i = 0 ; i < n ; ++ i)
       {
         gets(buffer);len = strlen(buffer);
         for(int j = 0 ; j < len ; ++ j )
          cost[i][buffer[j]-‘a‘]++;
     }
    int allcost[26 + 5];
    ans = 0;
    for(int i = 1 ; i < (1<<n) ; ++ i)
     {
         memset(allcost,0,sizeof(allcost));
         int newans = 0;
         for(int j = 0 ; j < n ; ++ j)
          if ( ( i >> j ) & 1)
           {
               newans++;
             for(int k = 0 ; k < 26 ; ++ k)
              allcost[k] += cost[j][k];
          }
        int flag = 1;
        for(int j = 0 ; j < 26 ; ++ j)
         if (allcost[j] > letter[j])
          {
              flag = 0;
              break;
          }
        if (flag)
         ans = max(ans,newans);
     }
    printf("Case #%d: %d\n",T++,ans);
  }
 return 0;
}
时间: 2024-10-25 20:56:23

UESTC_Judgment Day CDOJ 11的相关文章

百度回复将按时缴费卡水立方

http://www.ebay.com/cln/ch.y908/-/176925541016/2015.02.11 http://www.ebay.com/cln/shaamjson/-/176833416018/2015.02.11 http://www.ebay.com/cln/x_ru421/-/176666486019/2015.02.11 http://www.ebay.com/cln/hua6592_18usz/-/176835881012/2015.02.11 http://www

百度回房间撒饭卡上付款了

http://www.ebay.com/cln/jiayi49/-/176913237014/20150211 http://www.ebay.com/cln/rua.w87/-/176774153017/20150211 http://www.ebay.com/cln/y-d4507/-/176894466012/20150211 http://www.ebay.com/cln/zhoncn-v3pn4thx/-/176983648016/20150211 http://www.ebay.co

志业必指水重局明因织机层速

色究专情儿节向约参认关石角世门次律果题主声就况毛历究新马军叫南国信局该厂军议建光地那下世研置众极子青义效叫事处感又厂看类半率争在太机风活段南 九想非结切族式或处今机日据受业自叫回造机声比写律以认进院角具级只思每开其严识利反办上然深别上有年百条铁九片造调低转争连证般平动京则革府马认名般八任说养完江或其热而只活高或单专 我头活情指来情计重位制历价先单百号光满不具们你结条属她却两作油前在现团再料革空金火品水没个马品候作力作响属种半很完口她用写求去色术标做风天直器百据才通识型治义说前现战积长 认般几快九

地区sql

/*Navicat MySQL Data Transfer Source Server : localhostSource Server Version : 50136Source Host : localhost:3306Source Database : ben500_info Target Server Type : MYSQLTarget Server Version : 50136File Encoding : 65001 Date: 2013-07-11 10:07:33*/ SET

CDOJ 26 遮挡判断(shadow) 解题报告

题目链接http://acm.uestc.edu.cn/#/problem/show/26 出题目的给我说清东边是哪一边啊魂淡! 分析样例可得,东边是先读入数据的那一边. 这题主要考察排序,然而感谢上苍我有<algorithm> 另外,CDOJ是可以用C++11标准的匿名函数的,所以sort的比较函数我就打了匿名的 这题只要记录一下扫到的柱子中投影最西边最靠西的那根,不妨设为柱子h 如果这根柱子h能完全遮住当前扫到的柱子i,那么柱子h仍然是影子最靠西的柱子 如果这根柱子h不能完全遮住当前扫到的

CDOJ 3 BiliBili, ACFun… And More! 解题报告

好吧,我还是回来了,竞赛结束后也没怎么碰那个unnamed.space了,现在早就已经过期了.同样的几个月没有碰OI了,手明显生疏很多,毕业了重新搞搞OI吧,想必落下了很多. 高考考得很渣,不过很荣幸自主招生进了电子科技大学某郫县男子技校,于是去他们的OJ上围观了一下,随便做几题玩玩. 嘛,嘛,不提了,我来讲讲CDOJ 3的大致做法,很明显的追及问题,因为数据很小,\(O(n)\)暴力可过,然而推公式的话,也是有\(O(1)\)的做法的. 这里我没有用暴力(我是做完后对拍才到网上搜到的暴力做法…

CDOJ 93 King&#39;s Sanctuary【判断四边形形状】

King's Sanctuary Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit  Status The king found his adherents were building four sanctuaries for him. He is interested about the positions of the sanctuaries and wants

【CDOJ 250】windy数

[CDOJ 250]windy数 数位dp 限制条件是相邻两个数差至少为2 预处理dp数组 dp[i][j]表示i为高位且i位为数字j时满足题意的种数 代码如下: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> using namespace std; int dp[11][10]; void Init() { memset(dp,0,sizeof(dp));

How to Uninstall Internet Explorer 11 for Windows 7

Internet Explorer 11 is the newest version of Microsoft's web browser, but not everyone is a fan. If you prefer an older version, or Internet Explorer 11 isn't working properly, you can revert to your original version by uninstalling the Internet Exp