Hearthstone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 407 Accepted Submission(s): 167
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
Author
SYSU
Source
2016 Multi-University Training Contest 7
【题意】有a类卡片n张(效果:可以抽两张牌),b类卡片m张(效果:可以造成对手x点伤害),对手的hp是p,当小于等于0的时候就死亡了,问能在第一回合就杀死对手的概率是多少。(牌是随机打乱的,能量不限,开始可以抽一张牌)
【分析】因为n+m《=20 所以可以考虑状态压缩暴力,我们首先可以在外面打出一个表sign[i][j][k],代表n=i,m=j,当前正好可以取到k张牌的次数,然后我们可以枚举m的子集,并判断利用这些牌能否打败对手,那么(ans=sign[n][m][k]*a[k]*a[m-k]*a[n])/(n+m)!(a预处理的阶乘)。
代码:
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<iostream>
using namespace std;
typedef __int64 LL;
const int maxn = 1e3+10;
int sign[25][25][25];
int h[25];
LL a[25];
void ok(int x,int len)
{
int last=1;
int one=0;
int two=0;
LL sum=0;
for(int i=1; i<=len; i++)
{
if(x&1)
{
two++;
if(last>0)
last--,sum++;
}
else
{
one++;
if(last>0)
{
last++;
}
}
x>>=1;
}
sign[one][two][sum]++;
}
void init()
{
a[0]=1;
a[1]=1;
for(LL i=2; i<=21; i++)
a[i]=a[i-1]*i;
for(int len=1; len<=20; len++)
for(int i=0; i<(1<<(len)); i++)
{
ok(i,len);
}
}
int judge(LL x,LL m,LL p)
{
int sum,as;
int minsum;
minsum=1111111;
sum=as=0;
for(int i=1; i<=m; i++)
{
if(x&1)
{
sum+=h[i];
as++;
minsum=min(minsum,h[i]);
}
x>>=1;
}
if(sum>=p)
return as;
else return -1;
}
int main()
{
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
init();
LL T,p,n,m;
scanf("%I64d",&T);
while(T--)
{
scanf("%I64d%I64d%I64d",&p,&n,&m);
for(LL i=1; i<=m; i++)
scanf("%d",&h[i]);
if(p<=0)
{
printf("1/1\n");
continue;
}
LL zi=0;
for(LL i=0; i<(1<<m); i++)
{
int x=judge(i,m,p);
if(x!=-1)
{
zi+=sign[n][m][x]*a[x]*a[m-x]*a[n];
}
}
LL b=__gcd(zi,a[n+m]);
if(zi==0) printf("0/1\n");
else printf("%I64d/%I64d\n",zi/b,a[n+m]/b);
}
return 0;
}