hdu 5816 Hearthstone 状态dp
来源:互联网 发布:剑灵女灵族捏脸数据图 编辑:程序博客网 时间:2024/05/21 08:56
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
题意:给p,n,m三个数,分别表示敌人的血量,可抽A牌的数量(A牌可以再抽两张),可抽B牌的数量(B牌对敌人造成a[i]点伤害),问现在轮到我抽一张牌(抽了A牌后又可以抽2张,如此往复),问最后打死敌人的概率。
分析:分母是所有牌的全排列
分子是可行的方案数,考虑n,m不大,状压dp,把所有可行状态转移过来。只要A>当前的B+1,那么证明是还可以转移到下一个状态的,但是如果当前状态就已经可行的话,就不需要转移了,因为如果转移的话会和后面成功的状态后剩下的牌的全排列重复。
#include <bits/stdc++.h>using namespace std;typedef long long ll;ll dp[(1<<20)+100];int val[21];ll f[21];void init(){ f[0]=1; for(int i=1;i<=20;i++) f[i]=f[i-1]*(i*1LL);}ll gcd(ll a,ll b){ return b==0?a:gcd(b,a%b);}int main(){ int t; init(); scanf("%d",&t); while(t--){ int p,n,m; scanf("%d%d%d",&p,&n,&m); int N = (n+m); int end=(1<<N); for(int i=0;i<m;i++) { scanf("%d",&val[i]); } memset(dp,0,sizeof(dp)); dp[0]=1; for(int st=0;st<end;st++) { if(dp[st]==0) continue; int A=0,B=0,sum=0; for(int j=0;j<m;j++) { if((1<<j)&st) { sum+=val[j]; B++; } } if(sum>=p) continue; for(int j=m;j<N;j++) { if((1<<j)&st) { A++; } } if(A-B+1>0) { for(int j=0;j<N;j++) { if(!((1<<j)&st)) { dp[st^(1<<j)]+=dp[st];//当前状态牺牲一张A可以达到的后续,状态转移是每次转移一步 } } } } ll up=0,down=f[N]; for(int st=0;st<end;st++) { if(dp[st]==0) continue;//无用的状态直接跳过 达到剪枝的效果 int sum=0,A=0,B=0; for(int j=0;j<m;j++) { if((1<<j)&st) { sum+=val[j]; B++; } } for(int j=m;j<N;j++) { if((1<<j)&st) { A++; } } if(sum>=p) { up+=(ll)dp[st]*f[N-A-B]; } } ll g=__gcd(up,down); printf("%I64d/%I64d\n",up/g,down/g ); }}
- hdu 5816 Hearthstone 状态dp
- Hdu-5816 Hearthstone(状态压缩DP)
- HDU 5816 Hearthstone(状态压缩DP+概率)
- hdu 5816 Hearthstone (状压dp)
- [HDU 5816] Hearthstone (概率DP+状压)
- HDU 5816 Hearthstone (状压dp)
- HDU 5816 Hearthstone(概率DP+状压)
- HDU-5816-Hearthstone-DP+数学推导
- HDU 5816 Hearthstone (状压dp)
- HDU 5816 Hearthstone (状压dp+概率)
- HDU 5816 Hearthstone(状压DP)
- HDU 5816 Hearthstone (Probability dp, Conbinations)
- hdu5816 Hearthstone 状态压缩dp
- hdu 5816 Hearthstone 状压DP+记忆化搜索
- HDU 5816 Hearthstone
- HDU 5816 Hearthstone
- HDU 5816 Hearthstone
- (HDU 5816)2016 Multi-University Training Contest 7 Hearthstone (状压DP、搜索)
- Source Insight 3.5 序列号分享
- IDA学习-1
- HBase - 数据写入流程解析
- python基础(四)——正则表达式
- 特简单的opencv 与摄像头接口程序
- hdu 5816 Hearthstone 状态dp
- 一个简单效果用到的js特性(异步编程,匿名函数,闭包)
- 详细图解MySQL(win7x64 5.7.16版本)下载、安装、配置与使用
- leetcode他人总结
- [Leetcode] 207. Course Schedule 解题报告
- ofbiz UOM Conversion Relationship Not Found [单位转化关系没有找到] 问题解决:
- 89C52单片机之数码管
- 广度优先搜索
- android获取已安装应用大小补充