HDU 5816 Hearthstone

132 篇文章 0 订阅
39 篇文章 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
 


实在想不到好的办法,只好强行模拟用bfs+map怼过去了。

#include<set>
#include<map>
#include<ctime>
#include<cmath>
#include<stack>
#include<queue>
#include<bitset>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#define rep(i,j,k) for (int i = j; i <= k; i++)
#define per(i,j,k) for (int i = j; i >= k; i--)
#define lson x << 1, l, mid
#define rson x << 1 | 1, mid + 1, r
using namespace std;
typedef long long LL;
const int low(int x) { return x&-x; }
const double eps = 1e-8;
const int INF = 0x7FFFFFFF;
const int mod = 1e9 + 7;
const int N = 20;
int T, h, n, m;
int a[N], cas = 0;

struct point
{
    LL x, y;
    point(int x = 0, int y = 0) :x(x), y(y) {}
}ans;

struct status
{
    int x, y, z;
    status(int x = 0, int y = 0, int z = 0) :x(x), y(y), z(z) {};
    bool operator<(const status&a) const
    {
        return x == a.x ? y == a.y ? z < a.z : y < a.y : x < a.x;
    }
};

map<status, point> M;

LL gcd(LL x, LL y)
{
    return x%y ? gcd(y, x%y) : y;
}

point operator*(point a, point b)
{
    LL x = a.x*b.x;
    LL y = a.y*b.y;
    return point(x / gcd(x, y), y / gcd(x, y));
}

point operator+(point a, point b)
{
    LL x = a.x*b.y + a.y*b.x;
    LL y = a.y*b.y;
    return point(x / gcd(x, y), y / gcd(x, y));
}

int main()
{
    scanf("%d", &T);
    while (T--)
    {
        ans = point(0, 1);    M.clear();
        scanf("%d%d%d", &h, &n, &m);
        rep(i, 0, m - 1) scanf("%d", &a[i]);
        queue<status> p; 
        if (n) {
            M[status(1, 1, 0)] = point(n, m + n);
            p.push(status(1, 1, 0));
        }
        rep(i, 0, m - 1)
        {
            M[status(1, 0, 1 << i)] = point(1, m + n);
            p.push(status(1, 0, 1 << i));
        }
        while (!p.empty())
        {
            status q = p.front(); p.pop();
            int res = 0, cnt = 0;
            rep(i, 0, m - 1) res += (q.z & (1 << i)) ? (cnt++, a[i]) : 0;
            if (res >= h) 
            {
                ans = ans + M[q]; continue;
            }
            if (q.x == n + m || !q.y) continue;
            if (q.x == n + m - 1)
            {
                status r = status(q.x + 1, q.y - 1, (1 << m) - 1);
                if (!M.count(r)) { p.push(r); M[r] = point(0, 1); }
                M[r] = M[r] + M[q];
            }
            else
            {
                if (n - q.x + cnt >= 2)
                {
                    point w = point((n - q.x + cnt)*(n - q.x + cnt - 1), (n + m - q.x)*(n + m - q.x - 1));
                    status r = status(q.x + 2, q.y + 1, q.z);
                    if (!M.count(r)) { p.push(r); M[r] = point(0, 1); }
                    M[r] = M[r] + M[q] * w;
                }
                if (m - cnt >= 2)
                {
                    rep(i, 0, m - 1)
                    {
                        if (q.z & (1 << i)) continue;
                        rep(j, i + 1, m - 1)
                        {
                            if (q.z & (1 << j)) continue;
                            point w = point(2, (n + m - q.x)*(n + m - q.x - 1));
                            status r = status(q.x + 2, q.y - 1, q.z ^ (1 << i) ^ (1 << j));
                            if (!M.count(r)) { p.push(r); M[r] = point(0, 1); }
                            M[r] = M[r] + M[q] * w;
                        }
                    }
                }
                if (n - q.x + cnt >= 1 && m - cnt >= 1)
                {
                    rep(i, 0, m - 1)
                    {
                        if (q.z & (1 << i)) continue;
                        point w = point(2*(n - q.x + cnt), (n + m - q.x)*(n + m - q.x - 1));
                        status r = status(q.x + 2, q.y , q.z ^ (1 << i));
                        if (!M.count(r)) { p.push(r); M[r] = point(0, 1); }
                        M[r] = M[r] + M[q] * w;
                    }
                }
            }
        }
        printf("%lld/%lld\n", ans.x, ans.y);
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值