题目链接:

Hearthstone

Time Limit: 2000/1000 MS (Java/Others)  

  Memory Limit: 65536/65536 K (Java/Others)

Problem Description
Hearthstone is an online collectible card game from Blizzard Entertainment. Strategies and luck are the most important factors in this game. When you suffer a desperate situation and your only hope depends on the top of the card deck, and you draw the only 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.

 
Input
The first line is the number of test cases T (T<=10). 
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.
 
Output
For each test case, output the probability as a reduced fraction (i.e., the greatest common divisor of the numerator and denominator is 1). If the answer is zero (one), you should output 0/1 (1/1) instead.
 
Sample Input
2
3 1 2
1 2
3 5 10
1 1 1 1 1 1 1 1 1 1
 
Sample Output
1/3
46/273
 
题意:
 
给了n张A牌,m张B牌,A牌能取两张.B牌能打掉a[i]的血,问打掉至少p点血的概率是多少;
 
思路:
 
dp[i]表示i状态下的方案数,所求答案就是大于等于p点的状态的方案数总和与(n+m)!的比值;
状态的转移的话就是手中的A种牌在这个状态下是否还能拿牌,具体的可以看这个链接
 
AC代码:
 
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
//#include <bits/stdc++.h>
#include <stack>
#include <map> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=1e5+10;
const int maxn=(1<<20)+14;
const double eps=1e-12; LL dp[maxn],f[23];
int num[maxn],p,n,m,a[30];
inline void Init()
{
for(int i=0;i<maxn;i++)
{
for(int j=0;j<20;j++)
{
if(i&(1<<j))num[i]++;
}
}
f[0]=1;
for(int i=1;i<=20;i++)f[i]=f[i-1]*i;
}
int cal(int x)
{
int sum=0;
for(int i=0;i<m;i++)
{
if(x&(1<<i))sum+=a[i];
}
return sum;
} LL gcd(LL x,LL y)
{
if(y==0)return x;
return gcd(y,x%y);
}
int counter(int x)
{
int sum=0;
for(int i=0;i<m;i++)
{
if(x&(1<<i))sum++;
}
return num[x]-2*sum+1;
}
int main()
{
Init();
int t;
read(t);
while(t--)
{
mst(dp,0);
read(p);read(n);read(m);
For(i,0,m-1)read(a[i]);
LL ans=0;
int tot=(1<<(n+m))-1;
dp[0]=1;
for(int i=0;i<=tot;i++)
{
if(!dp[i])continue;
if(i==tot||counter(i)==0)
{
if(cal(i)>=p)ans=ans+dp[i]*f[n+m-num[i]];
}
else
{
for(int j=0;j<n+m;j++)
{
if(i&(1<<j))continue;
dp[i|(1<<j)]+=dp[i];
}
}
}
LL g=gcd(ans,f[n+m]);
cout<<ans/g<<"/"<<f[n+m]/g<<"\n";
}
return 0;
}

  

hdu-5816 Hearthstone(状压dp+概率期望)的更多相关文章

  1. 多校7 HDU5816 Hearthstone 状压DP+全排列

    多校7 HDU5816 Hearthstone 状压DP+全排列 题意:boss的PH为p,n张A牌,m张B牌.抽取一张牌,能胜利的概率是多少? 如果抽到的是A牌,当剩余牌的数目不少于2张,再从剩余牌 ...

  2. HDU 4336 容斥原理 || 状压DP

    状压DP :F(S)=Sum*F(S)+p(x1)*F(S^(1<<x1))+p(x2)*F(S^(1<<x2))...+1; F(S)表示取状态为S的牌的期望次数,Sum表示 ...

  3. BZOJ1076 [SCOI2008]奖励关 【状压dp + 数学期望】

    1076: [SCOI2008]奖励关 Time Limit: 10 Sec  Memory Limit: 128 MB Submit: 3074  Solved: 1599 [Submit][Sta ...

  4. HDU 4284Travel(状压DP)

    HDU 4284    Travel 有N个城市,M条边和H个这个人(PP)必须要去的城市,在每个城市里他都必须要“打工”,打工需要花费Di,可以挣到Ci,每条边有一个花费,现在求PP可不可以从起点1 ...

  5. HDU 3001 Travelling ——状压DP

    [题目分析] 赤裸裸的状压DP. 每个点可以经过两次,问经过所有点的最短路径. 然后写了一发四进制(真是好写) 然后就MLE了. 懒得写hash了. 改成三进制,顺利A掉,时间垫底. [代码] #in ...

  6. HDU - 5117 Fluorescent(状压dp+思维)

    原题链接 题意 有N个灯和M个开关,每个开关控制着一些灯,如果按下某个开关,就会让对应的灯切换状态:问在每个开关按下与否的一共2^m情况下,每种状态下亮灯的个数的立方的和. 思路1.首先注意到N< ...

  7. P4321-随机漫游【状压dp,数学期望,高斯消元】

    正题 题目链接:https://www.luogu.com.cn/problem/P4321 题目大意 给出\(n\)个点\(m\)条边的一张无向图,\(q\)次询问. 每次询问给出一个点集和一个起点 ...

  8. hdu 4114(状压dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4114 思路:首先是floyd预处理出任意两点之间的最短距离.dp[state1][state2][u] ...

  9. 【BZOJ】1076: [SCOI2008]奖励关(状压dp+数学期望)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1076 有时候人蠢还真是蠢.一开始我看不懂期望啊..白书上其实讲得很详细的,什么全概率,全期望(这个压 ...

随机推荐

  1. java 逻辑运算符 短路(条件操作)

    两个数字计算时都会先把数字转换成二进制后再进行换算,二进制就是由0和1组成的数字  http://yxwang0615.iteye.com/blog/1084288    

  2. Struts2学习三----------Action搜索顺序

    © 版权声明:本文为博主原创文章,转载请注明出处 Struts2的Action的搜索顺序 http://localhost:8080/path1/path2/student.action 1)判断pa ...

  3. linux SPI驱动——spi core(四)

    一: SPI核心,就是指/drivers/spi/目录下spi.c文件中提供给其他文件的函数,首先看下spi核心的初始化函数spi_init(void). 1: static int __init s ...

  4. 华为p20:拍美景,听讲解,旅行更智能

    华为P20轰轰烈烈地上市了,本来对手机并不感冒的我,看到身边的好友换了P20,不禁感慨:这个月的活又要白干了,全部都要上交给华为,因为这款手机完全戳中了旅游爱好者的痛点. 痛点一:丢弃笨重的单反,手机 ...

  5. centOS中修改语言环境

    在终端中打开 键入 vim ~/.bashrc 在最后一行键入 export LANG="zh_CH.UTF-8"

  6. git 工具 - 子模块(submodule)

    From: https://git-scm.com/book/zh/v2/Git-%E5%B7%A5%E5%85%B7-%E5%AD%90%E6%A8%A1%E5%9D%97 子模块 有种情况我们经常 ...

  7. cocos2d-x 下使用加密 sqlite3

    sqlite3 加密库用的是wxsqlite3-3.0.0.1 提取出来的, 在android 下測试通过,无异常 编译时仅仅须要编译  sqlite3secure.c  此文件,即能够成功.測试时生 ...

  8. Devexpress Spreadsheet 中文教程

    http://blog.csdn.net/hotmee/article/details/50554381

  9. android菜鸟学习笔记9----Activity(二)

    关于Activity的生命周期: 下面是Activity整个生命周期中,状态发生变化时所回调的方法,它们对应着Activity完整的生命过程. void  onCreate(Bundle savedI ...

  10. 九度OJ 1153:括号匹配问题 (DP)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5193 解决:2248 题目描述: 在某个字符串(长度不超过100)中有左括号.右括号和大小写字母:规定(与常见的算数式子一样)任何一个左括 ...