Hdu-5816 Hearthstone(状态压缩DP)

185 篇文章 0 订阅
116 篇文章 0 订阅
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张奥术智慧和m张值不同火球术,开始可以抽一张牌,问你干死p滴血的对手的概率。 分析:DP,f[x]表示现在已经抽的牌为x,然后找x中有几张a和b,那么你还能抽的次数为1+a-b,如果次数<0直接不合法退出,当手中b牌可以干死对手也要直接赋值。
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<stack>
#include<cmath>
#include<queue>
#define INF 0x3f3f3f3f
#define MAX 2147483647
#define eps 1e-9
#define MAXN 2000005
using namespace std;
int T,p,n,m,fa[MAXN],fb[MAXN],cost[MAXN],a[MAXN],zy[21];
long long f[MAXN],jc[21];
long long gcd(long long a,long long b)
{
	if(a % b == 0) return b;
	return gcd(b,a % b);
}
int main() 
{
	zy[0] = jc[0] = 1ll;
	for(int i = 1;i <= 20;i++) 
	{
		zy[i] = 1<<i;
		jc[i] = jc[i-1]*i;
	}
	scanf("%d",&T);
	while(T--)
	{
		memset(cost,0,sizeof(cost));
		memset(fa,0,sizeof(fa));
		memset(fb,0,sizeof(fb));
		memset(f,0,sizeof(f));
		scanf("%d%d%d",&p,&n,&m);
		for(int i = 1;i <= m;i++) 
		{
			int x;
			scanf("%d",&x);
			a[zy[i-1]] = x;
		}
		for(int i = 1;i <= (zy[n+m]) - 1;i++)
		{
			fa[i] = fa[i&(i-1)];
			fb[i] = fb[i&(i-1)];
			cost[i] = cost[i&(i-1)];
			int pos = i^(i&(i-1));
			if(pos >= zy[m]) fa[i]++;
			else
			{
				fb[i]++;
				cost[i] += a[pos];
			}
		}
		for(int i = (zy[n+m]) - 1;i >= 0;i--)
		{
			if(1 + fa[i] < fb[i]) continue;
			if(cost[i] >= p) 
			{
				f[i] = jc[n+m-fa[i]-fb[i]];
				continue;
			}
			if(1 + fa[i] == fb[i]) continue;
			for(int j = 1;j <= (n+m);j++)
			 if((i & zy[j-1]) == 0) f[i] += f[i | zy[j-1]];
		}
		long long a = f[0],b = jc[n+m];
		cout<<a/gcd(a,b)<<"/"<<b/gcd(a,b)<<endl;
	}
} 

 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值