HDU5816 Hearthstone
Hearthstone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1110 Accepted Submission(s): 548
card to solve this dilemma. We call this "Shen Chou Gou" in Chinese.

Now you are asked to calculate the probability to become a "Shen Chou Gou" to kill your enemy in this turn. To simplify this problem, we assume that there are only two kinds of cards, and you don't need to consider the cost of the cards.
-A-Card: If the card deck contains less than two cards, draw all the cards from the card deck; otherwise, draw two cards from the top of the card deck.
-B-Card: Deal X damage to your enemy.
Note that different B-Cards may have different X values.
At the beginning, you have no cards in your hands. Your enemy has P Hit Points (HP). The card deck has N A-Cards and M B-Cards. The card deck has been shuffled randomly. At the beginning of your turn, you draw a card from the top of the card deck. You can use
all the cards in your hands until you run out of it. Your task is to calculate the probability that you can win in this turn, i.e., can deal at least P damage to your enemy.

Then come three positive integers P (P<=1000), N and M (N+M<=20), representing the enemy’s HP, the number of A-Cards and the number of B-Cards in the card deck, respectively. Next line come M integers representing X (0<X<=1000) values for the B-Cards.
3 1 2
1 2
3 5 10
1 1 1 1 1 1 1 1 1 1
46/273
牌堆有n张奥术智慧,奥术智慧可以再从牌堆摸两张牌, m张伤害牌,伤害各为xi,初始从牌堆摸一张,问本回合能击杀给定hp的对手的概率,结果用分数表示。(n+m<=20)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <bitset> using namespace std; #define LL long long
const int INF = 0x3f3f3f3f;
#define MAXN 500 LL dp[1<<21];
LL f[22];
int d[20];
LL gcd(LL x,LL y)
{
return x?gcd(y%x,x):y;
} int main()
{
f[0]=1;
for(int i=1; i<21; i++)
f[i]=f[i-1]*i; int T,m,n,p;
for(scanf("%d",&T); T--;)
{
scanf("%d%d%d",&p,&n,&m);
for(int i=0; i<m; i++)
scanf("%d",&d[i]);
int N=m+n;
memset(dp,0,sizeof dp);
dp[0]=1;
for(int x=0; x<(1<<N); x++)
{
int a=0,b=0,k=0;
for(int i=0; i<m; i++)
{
if(x&(1<<i))
{
k+=d[i];
b++;
}
}
if(k>=p) continue;//伤害够了不抽了
for(int i=m; i<N; i++)
{
if(x&(1<<i))
{
a++;
}
}
if(a-b+1<=0) continue;//牌不能再抽了 for(int i=0;i<N;i++)
{
if(x&(1<<i)) continue;
dp[x^(1<<i)]+=dp[x];//在抽一张的状态数加上现在的状态
}
}
LL ans=0;
for(int x=0;x<(1<<N);x++)
{
if(dp[x]==0) continue;
int a=0,b=0,k=0;
for(int i=0; i<m; i++)
{
if(x&(1<<i))
{
k+=d[i];
b++;
}
}
if(k<p) continue;
for(int i=m; i<N; i++)
{
if(x&(1<<i))
{
a++;
}
}
if(a-b+1<0) continue;
ans+=dp[x]*f[N-a-b];
}
printf("%lld/%lld\n",ans/gcd(ans,f[N]),f[N]/gcd(ans,f[N]));
}
return 0;
}
HDU5816 Hearthstone的更多相关文章
- 多校7 HDU5816 Hearthstone 状压DP+全排列
多校7 HDU5816 Hearthstone 状压DP+全排列 题意:boss的PH为p,n张A牌,m张B牌.抽取一张牌,能胜利的概率是多少? 如果抽到的是A牌,当剩余牌的数目不少于2张,再从剩余牌 ...
- HDU5816 Hearthstone(状压DP)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5816 Description Hearthstone is an online collec ...
- hdu-5816 Hearthstone(状压dp+概率期望)
题目链接: Hearthstone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- HDU 5816 Hearthstone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Descript ...
- HDU 5816 Hearthstone (状压DP)
Hearthstone 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5816 Description Hearthstone is an onlin ...
- HDU 5816 Hearthstone 概率dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5816 Hearthstone Time Limit: 2000/1000 MS (Java/Othe ...
- Google Deepmind AI tries it hand at creating Hearthstone and Magic: The Gathering cards
http://www.techrepublic.com/article/google-deepmind-ai-tries-it-hand-at-creating-hearthstone-magic-t ...
- Programming a Hearthstone agent using Monte Carlo Tree Search(chapter one)
Markus Heikki AnderssonHåkon HelgesenHesselberg Master of Science in Computer Science Submission dat ...
- How to appraise Hearthstone card values
https://elie.net/blog/hearthstone/how-to-appraise-hearthstone-card-values/ In 2014, I became an avid ...
随机推荐
- nginx多域名、多证书
环境: 一台nginx服务器 192.168.10.251 两台windowsserver2012 IIS服务器 (192.168.10.252.192.168.10.253) 从阿里云上下载ssl证 ...
- Ionic2+WebApi 导出Excel转Pdf文件。
步骤: 1.首先在WebApi中先把excel生成好. 2.把excel转成Pdf,并返回下载的链接. 3.Ionic2的页面做好下载的接口. 嗯~思路很清晰,那么下面就来详细的操作吧. 以下是H5的 ...
- LeetCode Smallest Range
数据范围是3500,3500也就是说n的平方是可以接受的.这里告诉你就是有序的,也就是在提醒你可能会是一个类似于二分的算法,所以的话其实基于这两个认识的话我们就可以利用一个枚举叫二分的算法来解决这道题 ...
- Ubuntu 增加swap空间大小
1. create a 1G file for the swap. sudo fallocate -l 1G /swapfile we can verify that the correct amou ...
- SQL0803问题 键值重复
工作中遇到SQL0803问题 使用DB2AS400数据库 报数据库键值重复错误 经同事分析为索引的起始值与当前已有记录的最大索引值不匹配造成的,验证过程如下: 1.SELECT max(被索引字段) ...
- RabbitMQ的学习
生成者就是发送信息,消费者就是接收信息,队列就是存储数据的排队.消息通过你的应用程序和RabbitMQ进行传输,它们只能存储在队列中,队列容量没有限制,你要存储多少消息都可以——基本上是一个无限的缓冲 ...
- tomcat关闭时Log4j2报错 Log4j Log4j2-TF-4-Scheduled-1 memory leak
出错信息: 23-Sep-2017 17:43:18.964 警告 [main] org.apache.catalina.loader.WebappClassLoaderBase.clearRefer ...
- How to use BMW 35080 adapter with Yanhua Mini ACDP
I have a question about Yanhua Mini ACDP + module 4 BMW 35080 read and write: Can the 35080 adapter ...
- SQL Server数据库的兼容级别
SQL Server 是Microsoft 公司推出的关系型数据库管理系统.具有使用方便可伸缩性好与相关软件集成程度高等优点,可跨越从运行Microsoft Windows 98 的膝上型电脑到运行M ...
- 旅游类的APP原型模板分享——Priceline
Priceline是一款旅游服务的APP应用.功能有查找预订酒店.车票.机票等服务. 本原型由国产Mockplus(原型工具)和iDoc(智能标注,一键切图工具)提供. 先简单看看动图: 点击这里,可 ...