hdu 5816 Hearthstone( 2016 Multi-University Training Contest 7——暴力+dfs搜索)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5816

Hearthstone

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 628    Accepted Submission(s): 292


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
 
题目大意:有两种卡牌,摸到A牌效果是:再继续摸两张牌,使用B牌效果是:给对方造成x[i]点伤害。现在是你的回合,你从牌堆里膜一张牌,问能够给对方造成p点及p点以上伤害的概率。
将题目抽象成:两个数的比值:能造成p点及p点以上伤害的牌排列数/牌堆全排列数。
解题思路:
我一张一张的取,判断这张取的是a,我该怎么办,要是b,又该怎么办。直接暴力搜索即可。

详见代码。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

#define ll long long

int n,m,vis[1010],x[1010];
ll fac[50];

ll dfs(int p,int a,int b,int z,int h)
{
    if (p<=0)
        return fac[n+m-h]*(fac[n]/fac[a]);//后面无论怎么排列都赢了,所以加上剩下的全排列,以及前面取出的是a的全排列。
    if (z==0)
        return 0;
    ll s=0;
    if (a>0)
    s+=dfs(p,a-1,b,z+1,h+1);
    if (b>0)
    for (int i=1; i<=m; i++)
    {
        if (!vis[i])
        {
            vis[i]=1;
            s+=dfs(p-x[i],a,b-1,z-1,h+1);
            vis[i]=0;
        }
    }
    return s;
}

int main()
{
    fac[0]=1;
    for (int i=1;i<=20;i++)
    {
        fac[i]=i*fac[i-1];
    }
    int t;
    scanf("%d",&t);
    while (t--)
    {
        int p;
        memset(vis,0,sizeof(vis));
        scanf("%d%d%d",&p,&n,&m);//n张a,m张b
        ll fen=fac[n+m];
        for (int i=1; i<=m; i++)
        {
            scanf("%d",&x[i]);
        }
        ll ans=dfs(p,n,m,1,0);//p表示剩余血量,剩几张a,剩几张b,我可以拿几张,我已经拿了几张
        ll g=__gcd(fen,ans);
        printf ("%lld/%lld\n",ans/g,fen/g);
    }
    return 0;
}



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值