Hearthstone
Total Submission(s): 322 Accepted Submission(s): 139
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.
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.
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
Author
SYSU
Source
题目大意:
牌堆里有n张奥术智慧,m张火球术
跟炉石不同的是,m张火球术有各自的伤害。
当前敌人有血量Hp
问抽一张牌后,能干掉敌方的概率。
(抽到奥术智慧使用可多抽两张牌)
输出分数形式
因为 n+m≤20 并且 20! 刚好不爆long long
这样分母搞定后,分子即为所有能干掉对方的方案数。然后约个分就行。
求方案数可用dfs。
dp[x]
表示从x状态出发能打败敌方的概率。一开始用了二维表达当前剩余抽牌次数 后来发现没必要=。= 因为对于每个状态手中
i张a牌 j张b牌
来说,剩余的抽牌数量是一定的——
1+2∗j−i−j
这样瞎搜一下,记录一下降低时间就行了。
要注意的是当搜到杀死敌方的方案后,返回的不是1,而是剩余没抽的牌的组合。
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <algorithm>
#include <cmath>
#include <ctime>
#define LL long long
#define Pr pair<int,int>
#define fread(ch) freopen(ch,"r",stdin)
#define fwrite(ch) freopen(ch,"w",stdout)
using namespace std;
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const int mod = 1000000007;
LL xx[21];
LL dp[1<<20];
int dam[22];
int n,m,hp;
void init()
{
xx[0] = 1;
for(int i = 1; i <= 20; ++i)
xx[i] = xx[i-1]*i;
//printf("%lld\n",xx[20]);
}
LL dfs(int pos,int cost,int a,int b,int rest)
{
if(dp[pos] != -1) return dp[pos];
//printf("%d %d %d %d %d\n",pos,cost,a,b,rest);
if(cost >= hp) return dp[pos] = xx[n+m-a-b];
if(rest == 0 || a+b == n+m) return 0;
LL ans = 0;
for(int i = 0; i < n; ++i)
{
if(pos&(1<<i)) continue;
ans += dfs(pos|(1<<i),cost,a+1,b,rest+1);
}
for(int i = n; i < m+n; ++i)
{
if(pos&(1<<i)) continue;
ans += dfs(pos|(1<<i),cost+dam[i-n],a,b+1,rest-1);
}
return dp[pos] = ans;
}
int main()
{
//fread("");
//fwrite("");
init();
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&hp,&n,&m);
memset(dp,-1,sizeof(dp));
for(int i = 0; i < m; ++i)
scanf("%d",&dam[i]);
LL ans = dfs(0,0,0,0,1);
//printf("%lld\n",ans);
LL tmp = xx[n+m];
LL g = __gcd(ans,xx[n+m]);
ans /= g;
tmp /= g;
printf("%lld/%lld\n",ans,tmp);
}
return 0;
}