状态压缩。

每一个人所需的物品对应一个数字,统计一个每个数字有几个。每一种提供物品的状态也对应一个数字,然后暴力判断。

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; const int maxn = ;
int n, m, k;
int tot[maxn];
int ans;
int base[], y; int main()
{ while (~scanf("%d%d%d", &n, &m, &k)){
memset(tot, , sizeof tot); ans = ;
for (int i = ; i <= k; i++)
{
int t; scanf("%d", &t);
int state = ;
for (int j = ; j <= t; j++)
{
int x; scanf("%d", &x); x--;
state = state + ( << x);
}
tot[state]++;
} for (int i = ; i <= ( << n) - ; i++)
{
int tmp = i; y = ;
while (tmp) base[y++] = tmp % , tmp = tmp / ;
int num = ;
for (int i = ; i < y; i++) if (base[i]) num++;
if (num != m) continue; int ans_now = ;
for (int j = ; j <= i; j++)
if ((j|i)==i)
ans_now = ans_now + tot[j];
ans = max(ans, ans_now);
}
printf("%d\n", ans);
}
return ;
}

HUST 1371 Emergency relief的更多相关文章

  1. 1003. Emergency (25)

    As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...

  2. Emergency(山东省第一届ACM省赛)

    Emergency Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Kudo’s real name is not Kudo. H ...

  3. HUST 1017 - Exact cover (Dancing Links 模板题)

    1017 - Exact cover 时间限制:15秒 内存限制:128兆 自定评测 5584 次提交 2975 次通过 题目描述 There is an N*M matrix with only 0 ...

  4. 1003. Emergency

    As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...

  5. ubuntu 16.04 source (HUST and 163)

    #HUST deb http://mirrors.hust.edu.cn/ubuntu/ xenial main restricted universe multiverse deb http://m ...

  6. Dancing Link --- 模板题 HUST 1017 - Exact cover

    1017 - Exact cover Problem's Link:   http://acm.hust.edu.cn/problem/show/1017 Mean: 给定一个由0-1组成的矩阵,是否 ...

  7. PAT (Advanced Level) Practise 1003 Emergency(SPFA+DFS)

    1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...

  8. C3P0连接池问题,APPARENT DEADLOCK!!! Creating emergency..... [问题点数:20分,结帖人lovekong]

    采用c3p0连接池,每次调试程序,第一次访问时(Tomcat服务器重启后再访问)都会出现以下错误,然后连接库需要很长时间,最终是可以连上的,之后再访问就没问题了,请高手们会诊一下,希望能帮小弟解决此问 ...

  9. PAT 解题报告 1003. Emergency (25)

    1003. Emergency (25) As an emergency rescue team leader of a city, you are given a special map of yo ...

随机推荐

  1. Android OpenGL ES(八)绘制点Point ..

    上一篇介绍了OpenGL ES能够绘制的几种基本几何图形:点,线,三角形.将分别介绍这几种基本几何图形的例子.为方便起见,暂时在同一平面上绘制这些几何图形,在后面介绍完OpenGL ES的坐标系统和坐 ...

  2. Gym 100917C Constant Ratio 数论+暴力

    题目: Description standard input/outputStatements Given an integer n, find out number of ways to repre ...

  3. boost库之graph入门

    #include <boost/graph/undirected_graph.hpp> #include <boost/graph/adjacency_list.hpp> us ...

  4. Trie/最短的名字

    题目链接 /* 简单trie树的应用,注意在初始化的时候要把cnt也初始化,不然,WA! 下面的四分代码各有特点 */ //数组型,名字查询. #include<cstdio> #incl ...

  5. 自定义开关ToggleButton

    package com.example.test;import android.os.Bundle;import android.app.Activity;import android.view.Me ...

  6. final关键字修饰的变量

    final意义:最终的,不可改变的. 1.修饰变量,为常量,值不可变: 2.修饰对象,值可变,引用不变: 3.修饰方法,方法不可重写: 4.修饰类,无子类,不可以被继承,更不可能被重写. 1.fina ...

  7. 双重检查锁定与延迟初始化(转自infoq)

    很好的文章,转自http://www.infoq.com/cn/articles/double-checked-locking-with-delay-initialization 在java程序中,有 ...

  8. Magento首页显示产品

    Magento首页显示产品     经常用的比较琐碎,上官网发现一个稍微全一点的不过没有针对 具体使用过程中遇到的情况进行修正  这边只做一个备忘吧   (细节问题 按个别情况进行修改即可) New  ...

  9. java开发第一天

    今天是项目开始的时间,整体来说还是算顺利的.提前分好组,然后是听课时可以有人帮忙占座位的,感觉上是挺好的. 项目开发的难度看了看,由于有了第一次MFC开发的经验,所以这次听课感觉非常的有目标性,而且总 ...

  10. linq to sql DAL

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data. ...