Hearthstone
题意:
有$n$个无中生有,有$m$个不同的杀,第$i$个杀掉$X_i$滴血,敌人血量$P$,求问第一回合就将敌人杀死的概率是多少。
解法:
二进制枚举$A$类,$B$类卡的顺序,这样就确定了取了几个$B$卡,dp即可
$f(i,j)$表示选了$i$个卡,伤害和为$j$的方案数。
$ans = \sum {f(j,P)j!(m-j)!}$
总效率$O(n 2^{n+m})$
认真读题。
#include <iostream>
#include <cstdio>
#include <cstring> #define LL unsigned long long
#define N 23
#define bit(x) (1<<(x)) using namespace std; int P, n, m;
int X[N];
LL f[N][N][], comb[N][N], fac[N]; LL gcd(LL a, LL b) {
if (b == ) return a;
return gcd(b, a % b);
} int main() {
comb[][] = ;
fac[] = ;
for (int i = ; i <= ; i++) {
fac[i] = fac[i-] * i;
comb[i][] = ;
for (int j = ; j <= i; j++)
comb[i][j] = comb[i-][j-] + comb[i-][j];
}
int T;
scanf("%d", &T);
while (T--)
{
memset(f, , sizeof(f));
scanf("%d %d %d", &P, &n, &m);
X[] = ;
for(int i = ; i <= m; i++) scanf("%d", &X[i]);
f[][][] = ;
for(int i = ; i < m; i++)
for(int j = ; j <= i; j++)
for(int k = P; k >= ; k--)
{
f[i+][j][k] += f[i][j][k];
f[i+][j+][min(k+X[i+],P)] += f[i][j][k];
}
LL ans0 = , ans1 = ;
for(int S=;S<(<<(n+m));S++)
{
int cnt=,i,j=;
for(i=;i<n+m;i++) if(bit(i)&S) cnt++;
if(cnt!=m) continue;
ans1 += fac[m];
cnt=;
for(i=;i<n+m && cnt;i++)
{
if(bit(i)&S) cnt--, j++;
else cnt++;
}
ans0 += f[m][j][P] * fac[m-j] * fac[j];
}
if(ans0 == ) {
puts("0/1");
continue;
}
LL d = gcd(ans0, ans1);
cout << ans0/d << '/' << ans1/d << endl;
}
return ;
}
Hearthstone的更多相关文章
- HDU 5816 Hearthstone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Descript ...
- HDU5816 Hearthstone(状压DP)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5816 Description Hearthstone is an online collec ...
- 多校7 HDU5816 Hearthstone 状压DP+全排列
多校7 HDU5816 Hearthstone 状压DP+全排列 题意:boss的PH为p,n张A牌,m张B牌.抽取一张牌,能胜利的概率是多少? 如果抽到的是A牌,当剩余牌的数目不少于2张,再从剩余牌 ...
- HDU 5816 Hearthstone (状压DP)
Hearthstone 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5816 Description Hearthstone is an onlin ...
- HDU5816 Hearthstone
Hearthstone Time Limit: 2000/ ...
- HDU 5816 Hearthstone 概率dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5816 Hearthstone Time Limit: 2000/1000 MS (Java/Othe ...
- hdu-5816 Hearthstone(状压dp+概率期望)
题目链接: Hearthstone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- Google Deepmind AI tries it hand at creating Hearthstone and Magic: The Gathering cards
http://www.techrepublic.com/article/google-deepmind-ai-tries-it-hand-at-creating-hearthstone-magic-t ...
- Programming a Hearthstone agent using Monte Carlo Tree Search(chapter one)
Markus Heikki AnderssonHåkon HelgesenHesselberg Master of Science in Computer Science Submission dat ...
- How to appraise Hearthstone card values
https://elie.net/blog/hearthstone/how-to-appraise-hearthstone-card-values/ In 2014, I became an avid ...
随机推荐
- C语言-二维背包问题
二维费用背包问题 问题: 二维费用的背包问题是指:对于每件物品,具有两种不同的费用:选择这件物品必须同时付出这两种代价:对于每种代价都有 一个可付出的最大值(背包容量).问怎样选择物品可以得到最大的价 ...
- nodejs 模板字符串
范例1: for (var i=0;i<10;i++){ var data = `公司名:${i}`; console.log(data) } 输出: 实例2: var name = '丁香医生 ...
- AVL平衡树的插入例程
/* **AVL平衡树插入例程 **2014-5-30 11:44:50 */ avlTree insert(elementType X, avlTree T){ if(T == NULL){ T = ...
- libraries_v140_x64_py35_1.0.1.tar.bz2 libraries_v120_x64_py27_1.1.0.tar 下载链接以及百度云下载链接
下载链接 wget -c https://github.com/willyd/caffe-builder/releases/download/v1.0.1/libraries_v140_x64_p ...
- Java的泛型约束和限制
不能用基本类型实例化类型参数 不能用类型参数代替基本类型:例如,没有Pair<double>,只有Pair<Double>,其原因是类型擦除.擦除之后,Pair类含有Objec ...
- Operation not permitted - /usr/bin/pod
问题描述:执行sudo gem install cocoapods, 提示出错:While executing gem ... (Errno::EPERM) Operation not per ...
- [Phoenix] 六、MR在Ali-Phoenix上的使用
摘要: 在云HBASE上利用MR BULKLOAD入库PHOENIX表或通过MR构建PHOENIX索引表. 一.MR在Phoenix上的用途 利用MR对Phoenix表(可带有二级索引表)进行Bulk ...
- win7和win2008 r2下配置IIS7(ASP.net运行环境)
win7和win2008 r2下配置IIS7(ASP.net运行环境) 1.先要设置应用程序池(ApplicationPool)为Classic.NETAppPool,而不是默认的DefaultApp ...
- Android开发之onMeasure(int widthMeasureSpec, int heightMeasureSpec)方法
onMeasure()函数由包含这个View的具体的ViewGroup调用,因此值也是由其ViewGroup中传入的.子类View的这两个参数widthMeasureSpec, heightMeasu ...
- 【bzoj2286】[Sdoi2011]消耗战
虚树入门题: #include<cstdio> #include<cstring> #include<algorithm> #include<ctime> ...