HDU 5816 Hearthstone

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

题目大意:
你在玩炉石,对手n滴血,你每次抽的卡有两种类型,一种类型是再抽两张,另一种类型是能打对手x点伤害,x会一一给出,问能一回合击败对手的可能性是多少。

解题思路:

这道题是3^n的算法。。。
i代表当前抽到牌的集合
dp[i]代表抽到这种牌有多少种抽法,枚举每一种情况,如果能打死对手,则答案数加上dp[i]*fact[t],fact[t]代表t的阶乘,t是还剩t张抽完,
再判断当前拥有的牌是否合法,比如不能只摸到两张伤害牌,如果合法,则向下转移,计算出下一种牌有多少种模法
if(!((i>>j)&1)) dp[i|(1<

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#define RI(N) scanf("%d",&(N))
#define RII(N,M) scanf("%d %d",&(N),&(M))
#define RIII(N,M,K) scanf("%d %d %d",&(N),&(M),&(K))
#define mem(a) memset((a),0,sizeof(a))
using namespace std;
const int inf=1e9;
const int inf1=-1*1e9;
double EPS=1e-10;
typedef long long LL;

LL fact[25];
LL dp[(1<<20)+5];
int dam[25];
LL tot;
int p,n,m;
void ini()
{
    fact[0]=1;
    LL t=1;
    for(int i=1; i<=20; i++)
        {
            t*=i;
            fact[i]=t;
        }
}

bool check(LL x)
{
    int damm=0;
    for(int i=0; i<m; i++)
    {
        if((x>>i)&1) damm+=dam[i];
    }
    if(damm>=p) return true;
    return false;
}
LL cal(LL x)
{
    LL num=0;
    while(x)
    {
        num++;
        x&=(x-1);
    }
    return num;
}

LL gcd(LL a,LL b)
{
    if(b==0) return a;
    return gcd(b,a%b);
}
int main()
{
    ini();
    int T;
    RI(T);
    while(T--)
    {

        scanf("%d %d %d",&p,&n,&m);
        for(int i=0; i<m; i++)
            RI(dam[i]);
        memset(dp,0,sizeof(dp));
        LL tot=1<<(m+n);
        LL ans=0;
        for(int i=0; i<(n+m); i++) dp[1<<i]=1;
        for(int i=0; i<tot; i++)
        {
            if(check(i))
            {
                int t=m+n-cal(i);
                ans=ans+fact[t]*dp[i];
                continue;
            }
            int aa=0,bb=0;
            for(int j=m; j<m+n; j++)
            {
               if((i>>j)&1) aa++;
            }
            if(aa*2+1<=cal(i)) continue;
            for(int j=0; j<m+n; j++)
                if(!((i>>j)&1)) dp[i|(1<<j)]+=dp[i];
        }

        LL k=gcd(fact[n+m],ans);
        printf("%I64d/%I64d\n",ans/k,fact[n+m]/k);
    }
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值