---恢复内容开始---

Hearthstone

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

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可以对地方造成xi点伤害,给出A的剩余数量和B的剩余数量以及对手HP,求一回合胜利的概率。

---恢复内容结束---

Hearthstone

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

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可以对地方造成xi点伤害,给出A的剩余数量和B的剩余数量以及对手HP,求一回合胜利的概率。

暴力做法,我们枚举所有可能出现的集合,dp[S]表示S中的元素可组成的排列组合个数。

计算dp数组时采用的是我为人人型递推,if当前集合伤害大于P,或者没有抽牌的能力直接continue;

否则枚举所有他可能抽到的牌对新产生的集合(当前集合加上新抽的牌)加上当前集合的方案数;

之后遍历所有集合,如果这个集合造成的伤害大于等于P,就把dp[i]*f[N-|S|]加入分子,最后分母为(n+m)!;

ans+=dp[S]*f[N-|S|];

#include<bits/stdc++.h>
using namespace std;
#define LL long long
using namespace std;
LL dp[1<<20+1],f[22]={1,1};
int x[25];
int main()
{
    int N,n,m,i,j,p,k,t;
    for(LL i=2;i<=20;++i) f[i]=f[i-1]*i;
    cin>>t;
    while(t--){memset(dp,0,sizeof(dp));dp[0]=1;
        cin>>p>>n>>m;
        N=n+m;
        for(i=n+1;i<=N;++i) cin>>x[i];
        for(i=0;i<(1<<N);++i){
            if(!dp[i]) continue;
            int a=0,b=0,c=0;
            for(j=0;j<m;++j){
                if(i&(1<<j)) {
                        c+=x[N-j];
                        ++b;
                }
            }
            if(c>=p) continue;
            for(j=m;j<N;++j){
                if(i&(1<<j)) a++;
            }
            if(a-b+1<1) continue;
            for(j=0;j<N;++j){
               if(i&(1<<j)) continue;
               dp[i^(1<<j)]+=dp[i];
            }
        }LL xx=0,yy=f[N];
        for(i=0;i<(1<<N);++i){
            if(!dp[i]) continue;
            int a=0,b=0,c=0,s=0;
            for(j=0;j<N;++j) if(i&(1<<j)) s++;
            for(j=0;j<m;++j){
                if(i&(1<<j)) c+=x[N-j];
            }
            if(c<p) continue;
            xx+=dp[i]*f[N-s];
        }
        
        LL tp=__gcd(xx,yy);
        if(xx==0) yy=1;
        else {xx/=tp;yy/=tp;}
        printf("%lld/%lld\n",xx,yy);
    }
    return 0;
}

HDU 5816 状压DP&排列组合的更多相关文章

  1. HDU 4778 状压DP

    一看就是状压,由于是类似博弈的游戏.游戏里的两人都是绝对聪明,那么先手的选择是能够确定最终局面的. 实际上是枚举最终局面情况,0代表是被Bob拿走的,1为Alice拿走的,当时Alice拿走且满足变换 ...

  2. HDU 3001 状压DP

    有道状压题用了搜索被队友骂还能不能好好训练了,, hdu 3001 经典的状压dp 大概题意..有n个城市 m个道路  成了一个有向图.n<=10: 然后这个人想去旅行.有个超人开始可以把他扔到 ...

  3. hdu 2809(状压dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2809 思路:简单的状压dp,看代码会更明白. #include<iostream> #in ...

  4. hdu 2167(状压dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2167 思路:经典的状压dp题,前后,上下,对角8个位置不能取,状态压缩枚举即可所有情况,递推关系是为d ...

  5. Engineer Assignment HDU - 6006 状压dp

    http://acm.split.hdu.edu.cn/showproblem.php?pid=6006 比赛的时候写了一个暴力,存暴力,过了,还46ms 那个暴力的思路是,预处理can[i][j]表 ...

  6. hdu 3254 (状压DP) Corn Fields

    poj 3254 n乘m的矩阵,1表示这块区域可以放牛,0,表示不能,而且不能在相邻的(包括上下相邻)两个区域放牛,问有多少种放牛的方法,全部不放也是一种方法. 对于每块可以放牛的区域,有放或者不放两 ...

  7. HDU 5823 (状压dp)

    Problem color II 题目大意 定义一个无向图的价值为给每个节点染色使得每条边连接的两个节点颜色不同的最少颜色数. 对于给定的一张由n个点组成的无向图,求该图的2^n-1张非空子图的价值. ...

  8. hdu 4739 状压DP

    这里有状态压缩DP的好博文 题目:题目比较神,自己看题目吧 分析: 大概有两种思路: 1.dfs,判断正方形的话可以通过枚举对角线,大概每次减少4个三角形,加上一些小剪枝的话可以过. 2.状压DP,先 ...

  9. Travel(HDU 4284状压dp)

    题意:给n个城市m条路的网图,pp在城市1有一定的钱,想游览这n个城市(包括1),到达一个城市要一定的花费,可以在城市工作赚钱,但前提有工作证(得到有一定的花费),没工作证不能在该城市工作,但可以走, ...

随机推荐

  1. SIFT算法的教程及源码

    1.ubc:DAVID LOWE---SIFT算法的创始人,两篇巨经典经典的文章http://www.cs.ubc.ca/~lowe/[1] 2.cmu:YanKe---PCASIFT,总结的SIFT ...

  2. python重定向sys.stdin、sys.stdout和sys.stderr

    转自:https://www.cnblogs.com/guyuyuan/p/6885448.html 标准输入.标准输出和错误输出. 标准输入:一般是键盘.stdin对象为解释器提供输入字符流,一般使 ...

  3. Linux squid 缓存服务器

    一.简介 代理服务器英文全称是Proxy Server,其功能就是代理网络用户去取得网络信息. Squid是一个缓存Internet 数据的软件,其接收用户的下载申请,并自动处理所下载的数据.当一个用 ...

  4. D2 Magic Powder -1/- 2---cf#350D2(二分)

    题目链接:http://codeforces.com/contest/670/problem/D2 This problem is given in two versions that differ ...

  5. PHP之设计模式

    https://blog.csdn.net/self_realian/article/details/78228733 掌握PHP各类设计模式,具备设计纯面向对象框架和系统能力是非常有必要的.给大家一 ...

  6. java构建树用的Node

    package org.ccnt.med.body; import java.util.ArrayList; import java.util.List; public class Node { // ...

  7. Windows2003 + IIS6 安装.Net FrameWork 4.0 兼容早期版本的测试

    看到文档说.net4的框架可以向下兼容2.0.3.0.3.5这几个版本,觉得是一件好事,以后服务器上就不用费时费力的安装 2.0.3.5之类的框架了.但是又觉得奇怪,2.0和3.5的框架都是很大的,为 ...

  8. 78. Subsets(回溯)

      Given a set of distinct integers, nums, return all possible subsets (the power set). Note: The sol ...

  9. hdu5139

    这题需要我们计算 这个 因为n<10000000空间过大 那么我们可以计算出 当n可以被10整除的时候我们就将n/10记录下来当我们要查询的时候去暴力计算他们与整十之间的数去暴力去做就好了 这个 ...

  10. java提升路线

    转载自:http://blog.csdn.net/a151296/article/details/43658853 作为一名即将从事java开发的应届毕业生,迷茫中,转载此篇文章,作为提升自己的学习方 ...