hdu 4778 Gems Fight! 状态压缩DP
Gems Fight!
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 327680/327680 K (Java/Others)
Total Submission(s): 1069 Accepted Submission(s): 456
There are Gems of G different colors , packed in B bags. Each bag has several Gems. G different colors are numbered from color 1 to color G.
Alice and Bob take turns to pick one bag and collect all the Gems inside. A bag cannot be picked twice. The Gems collected are stored in a shared cooker.
After a player ,we name it as X, put Gems into the cooker, if there are S Gems which are the same color in the cooker, they will be melted into one Magic Stone. This reaction will go on and more than one Magic Stone may be produced, until no S Gems of the same color remained in that cooker. Then X owns those new Magic Stones. When X gets one or more new Magic Stones, he/she will also get a bonus turn. If X gets Magic Stone in a bonus turn, he will get another bonus turn. In short,a player may get multiple bonus turns continuously.
There will be B turns in total. The goal of "Gems Fight!" is to get as more Magic Stones than the opponent as possible.
Now Alice gets the first turn, and she wants to know, if both of them act the optimal way, what will be the difference between the number of her Magic Stones and the number of Bob's Magic Stones at the end of the game.
In each case, there are three integers at the first line: G, B, and S. Their meanings are mentioned above.
Then B lines follow. Each line describes a bag in the following format:
n c1 c2 ... cn
It means that there are n Gems in the bag and their colors are color c1,color c2...and color cn respectively.
0<=B<=21, 0<=G<=8, 0<n<=10, S < 20.
There may be extra blank lines between cases. You can get more information from the sample input.
The input ends with G = 0, B = 0 and S = 0.
2 2 3
2 1 3
2 1 2
3 2 3 1
3 2 2
3 2 3 1
3 1 2 3
0 0 0
-3
For the first case, in turn 2, bob has to choose at least one bag, so that Alice will make a Magic Stone at the end of turn 3, thus get turn 4 and get all the three Magic Stones.
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
#define INF 0xffffff
struct abcd
{
int a[];
}p[];
int g,b,s,x;
int dp[<<],bb[];
int main()
{
// freopen("in.txt","r",stdin);
int i,j,k,cnt,m;
while(scanf("%d%d%d",&g,&b,&s),(g|b|s))
{
memset(p,,sizeof(p));
for(i=;i<b;i++)
{
scanf("%d",&m);
for(j=;j<m;j++)
{
scanf("%d",&x);
p[i].a[x]++;
}
}
for(i=;i<(<<b);i++)
dp[i]=-INF;
dp[]=;
for(i=;i<(<<b);i++)
{
memset(bb,,sizeof(bb));
for(j=;j<b;j++)
{
if(!(i&(<<j)))
{
for(k=;k<=g;k++)
bb[k]+=p[j].a[k];
}
}
for(j=;j<=g;j++)bb[j]%=s;
for(j=;j<b;j++)
{
if((i&(<<j)))
{
cnt=;
for(k=;k<=g;k++)
{
cnt+=(bb[k]+p[j].a[k])/s;
}
if(cnt)
dp[i]=max(dp[i],dp[i^(<<j)]+cnt);
else dp[i]=max(dp[i],-dp[i^(<<j)]);
}
}
}
printf("%d\n",dp[(<<b)-]);
} }
hdu 4778 Gems Fight! 状态压缩DP的更多相关文章
- Hdu 4778 Gems Fight! (状态压缩 + DP)
题目链接: Hdu 4778 Gems Fight! 题目描述: 就是有G种颜色,B个背包,每个背包有n个宝石,颜色分别为c1,c2............两个人轮流取背包放到公共容器里面,容器里面有 ...
- hdu 4778 Gems Fight! 状压dp
转自wdd :http://blog.csdn.net/u010535824/article/details/38540835 题目链接:hdu 4778 状压DP 用DP[i]表示从i状态选到结束得 ...
- hdu 4778 Gems Fight! 博弈+状态dp+搜索
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4102743.html 题目链接:hdu 4778 Gems Fight! 博弈+状态dp+搜 ...
- HDU 4511 (AC自动机+状态压缩DP)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4511 题目大意:从1走到N,中间可以选择性经过某些点,比如1->N,或1->2-> ...
- HDU 3001 Travelling(状态压缩DP+三进制)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3001 题目大意:有n个城市,m条路,每条路都有一定的花费,可以从任意城市出发,每个城市不能经过两次以上 ...
- hdu 4057(ac自动机+状态压缩dp)
题意:容易理解... 分析:题目中给的模式串的个数最多为10个,于是想到用状态压缩dp来做,它的状态范围为1-2^9,所以最大为2^10-1,那我们可以用:dp[i][j][k]表示长度为i,在tri ...
- HDU 4778 Gems Fight! (2013杭州赛区1009题,状态压缩,博弈)
Gems Fight! Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 327680/327680 K (Java/Others)T ...
- hdu 2825(ac自动机+状态压缩dp)
题意:容易理解... 分析:在做这道题之前我做了hdu 4057,都是同一种类型的题,因为题中给的模式串的个数最多只能为10个,所以我们就很容易想到用状态压缩来做,但是开始的时候我的代码超时了dp时我 ...
- HDU 1074 Doing Homework (状态压缩 DP)
题目大意: 有 n 项作业需要完成,每项作业有上交的期限和需完成的天数,若某项作业晚交一天则扣一分.输入每项作业时包括三部分,作业名称,上交期限,完成所需要的天数.求出完成所有作业时所扣掉的分数最少, ...
随机推荐
- 利用wireshark任意获取qq好友IP实施精准定位
没事玩一把,感觉还挺有趣,首先打开wireshark: 不管你连接的什么网,如图我连接的是WLAN,双击进入如图界面: ctrl-f进行搜索:如图 选择分组详情,字符串,并输入020048.这时候你就 ...
- Maven项目下update maven后Eclipse报错:java.lang.ClassNotFoundException: ContextLoaderL
Maven项目下update maven后Eclipse报错:java.lang.ClassNotFoundException: ContextLoaderL 严重: Error config ...
- HTML+CSS画一朵向日葵
前几天看到一张图片,倔强的向日葵.(BGM,<倔强>) 看着挺有感触,就想用CSS做一个向日葵. 最终效果图如下: 主要的难点就在花瓣的处理上,css暂时没有做到这样的尖角圆弧. 我想到的 ...
- 最新Windows下Redis集群
实现简单的Windows下Redis集群配置,以下是配置过程中出现的几个问题: [1]逐个启动7001 7002 7003 7004 7005 7006节点时,出现createing server T ...
- webmagic爬取渲染网站
最近突然得知之后的工作有很多数据采集的任务,有朋友推荐webmagic这个项目,就上手玩了下.发现这个爬虫项目还是挺好用,爬取静态网站几乎不用自己写什么代码(当然是小型爬虫了~~|). 好了,废话少说 ...
- Flask04 后台获取请求数据、视图函数返回类型、前台接受响应数据
1 后台获取请求数据 1.1 提出问题 前台发送请求的方式有哪些 后台如何获取这些请求的参数 1.2 前台发送请求的方式 GET.POST.AJAX 点睛:如果不指定请求方式,浏览器默认使用GET请求 ...
- Makefile中export分析
在分析内核启动过程的./arch/arm/Makefile文件里碰到了这样字段 162 export TEXT_OFFSET GZFLAGS MMUEXT 然后在子目录arch/arm/kernel/ ...
- 基于C语言的UTF-8中英文替换密码设计
简要说明 本设计为湖南大学密码学的一次课程作业设计.非作业目的可随意引用. 由于本人初次接触密码学,本设计可能存在问题以及漏洞.若发现望指出. GitHub : https://github.com/ ...
- 1st_homework_SE--四则运算题目生成器
0x00 Code 查询源代码及README请点此 0x01 需求分析 实现一个自动生成小学四则运算题目的命令行程序. 0x02 功能设计 主要功能为: 接受用户输入以便知道要出多少道题目python ...
- 201521123065《java程序设计》第14周学习总结
1. 本周学习总结 1.大部分情况下使用的数据库是关系型的数据库,使用表存储数据: 2.关系型数据库可以通过唯一的主键查找记录,也可以通过多个信息确定主键: 3.Mysql操作:显示-show dat ...