#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <string.h>
using namespace std;
bool use[<<];
int dp[<<];
int G,B,S;
int P[][];
int nu[];
int work3()
{
int ans=;
for(int i=; i<=G; i++)
{
int ge=;
for(int j=;j <B; j++)
ge+=P[j][i];
ans+=ge/S;
}
return ans;
}
int jia(int j)
{
int ans=;
for(int i=; i<=G; i++)
{
nu[i]+=P[j][i];
ans+=nu[i]/S;
nu[i]%=S;
}
return ans;
}
void jian(int j)
{
for(int i=; i<=G; i++)
{
nu[i]=((nu[i]-P[j][i])%S+S)%S;
}
}
void dfs(int D,int cntge)
{
if(use[D])return ;
use[D]=true;
dp[D]=;
for(int j=;j<B; j++)
{
if((D&(<<j))==)continue;
int num=jia(j);
dfs(D^(<<j),cntge-num);
if(num>)
dp[D]=max(dp[D^(<<j)]+num,dp[D]);
else{
dp[D]=max(cntge-dp[D^(<<j)],dp[D]);
}
jian(j);
}
}
int main()
{ while(scanf("%d%d%d",&G,&B,&S)&&G+B+S!=)
{
if(B==){
printf("0\n");continue;
}
for(int i=; i<B; i++)
{
int d;
scanf("%d",&d);
memset(P[i],,sizeof(P[i]));
for(int j=;j<d; j++){
int k;scanf("%d",&k);
P[i][k]++;
}
}
int K=<<B;
memset(use,false,sizeof(use));
use[]=true;
int ge1=work3();
dfs(K-,ge1);
int ge=dp[K-];
printf("%d\n",ge*-ge1);
} return ;
}

hdu4778 状态压缩的更多相关文章

  1. hdu4778(状态压缩dp)

    题意: 有G种颜色的宝石,共B袋.两个人轮流拿宝石,每次从B袋中拿一袋,把其中的所有宝石倒入一个公共容器,每袋宝石只能取一次. 当容器中有S个相同颜色的宝石时,将失去这S个宝石,当前操作者得到一个魔法 ...

  2. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  3. HDU 3605:Escape(最大流+状态压缩)

    http://acm.hdu.edu.cn/showproblem.php?pid=3605 题意:有n个人要去到m个星球上,这n个人每个人对m个星球有一个选择,即愿不愿意去,"Y" ...

  4. [HDU 4336] Card Collector (状态压缩概率dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题目大意:有n种卡片,需要吃零食收集,打开零食,出现第i种卡片的概率是p[i],也有可能不出现卡 ...

  5. HDU 4336 Card Collector (期望DP+状态压缩 或者 状态压缩+容斥)

    题意:有N(1<=N<=20)张卡片,每包中含有这些卡片的概率,每包至多一张卡片,可能没有卡片.求需要买多少包才能拿到所以的N张卡片,求次数的期望. 析:期望DP,是很容易看出来的,然后由 ...

  6. codeforces B - Preparing Olympiad(dfs或者状态压缩枚举)

    B. Preparing Olympiad You have n problems. You have estimated the difficulty of the i-th one as inte ...

  7. NOIP2005过河[DP 状态压缩]

    题目描述 在河上有一座独木桥,一只青蛙想沿着独木桥从河的一侧跳到另一侧.在桥上有一些石子,青蛙很讨厌踩在这些石子上.由于桥的长度和青蛙一次跳过的距离都是正整数,我们可以把独木桥上青蛙可能到达的点看成数 ...

  8. vijos1426兴奋剂检查(多维费用的背包问题+状态压缩+hash)

    背景 北京奥运会开幕了,这是中国人的骄傲和自豪,中国健儿在运动场上已经创造了一个又一个辉煌,super pig也不例外……………… 描述 虽然兴奋剂是奥运会及其他重要比赛的禁药,是禁止服用的.但是运动 ...

  9. hoj2662 状态压缩dp

    Pieces Assignment My Tags   (Edit)   Source : zhouguyue   Time limit : 1 sec   Memory limit : 64 M S ...

随机推荐

  1. LeetCode 566 Reshape the Matrix 解题报告

    题目要求 In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a ...

  2. LeetCode 821 Shortest Distance to a Character 解题报告

    题目要求 Given a string S and a character C, return an array of integers representing the shortest dista ...

  3. 主动触发input框的失去焦点事件,阻止输入法跳出

    今天遇到个问题,我在手机做一个选择生日的功能,但是当我点击input框时,事件选择插件和输入法都弹出来了,很丑,然后就想阻止输入法弹出来, 网上一个方法是:在input框的获取焦点事件里,主动触发失去 ...

  4. 剑指offer-合并两个排列的链接

    题目描述 输入两个单调递增的链表,输出两个链表合成后的链表,当然我们需要合成后的链表满足单调不减规则.   public ListNode Merge(ListNode list1,ListNode ...

  5. 火币网API文档——WebSocket API简介

    WebSocket API简介 WebSocket协议是基于TCP的一种新的网络协议.它实现了客户端与服务器之间在单个 tcp 连接上的全双工通信,由服务器主动发送信息给客户端,减少了频繁的身份验证等 ...

  6. shell脚本编写实例

    实际案例 1.判断接收参数个数大于1 [ $# -lt 1 ] && echo "至少需要一个参数" && { echo "我要退出了.. ...

  7. (转)github设置添加SSH

    很多朋友在用github管理项目的时候,都是直接使用https url克隆到本地,当然也有有些人使用 SSH url 克隆到本地.然而,为什么绝大多数人会使用https url克隆呢? 这是因为,使用 ...

  8. dll相关总结

    1.动态链接库的使用有两种方式,一种是显式调用.一种是隐式调用. (1) 显式调用:使用LoadLibrary载入动态链接库.使用GetProcAddress获取某函数地址. (2) 隐式调用:可以使 ...

  9. [py]python写一个通讯录step by step V3.0

    python写一个通讯录step by step V3.0 参考: http://blog.51cto.com/lovelace/1631831 更新功能: 数据库进行数据存入和读取操作 字典配合函数 ...

  10. iot-dm异常日志

    iot-dm 本机断网日志 2018-03-15 08:55:41,345 INFO com.inspur.iot.client.core.IotConnection Connection is be ...