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 ...
随机推荐
- Nginx学习——进程模型(master 进程)
进程模型 Nginx分为Single和Master两种进程模型.Single模型即为单进程方式工作,具有较差的容错能力,不适合生产之用.Master模型即为一个master进程+N个worker进程的 ...
- C/C++,java开源数学计算库
有限元分析.数值计算.三维建模.信号处理.性能分析.仿真分析...这些或多或少与我们常用的软件息息相关,假如有一天你只需要这些大型软件系统的某一个很有限的功能,你是不是也要因此再用一用那动辄几个g的软 ...
- Centos7安装配置ansible运维自动化工具
准备至少两台机器 Centos7,这两台机器都关闭 selinux IP:106.13.118.132 服务端(ansible) masterIP:148.70.60.244 节点 slaver 服务 ...
- vue 生命周期钩子
每个vue实例被创建时都会经历一系列初始化的过程,像是一个生命从无到有的过程,所以叫生命周期,而这个过程都有对应的不同阶段,也就对应了生命周期不同的钩子函数,这些生命周期函数,作为vue实例的属性使用 ...
- ios 使用自定义字体
本文转载至 http://blog.csdn.net/yesjava/article/details/8447596 1.下载要使用的自定义字体,格式通常为ttf.otf文件.这里假设是nokia ...
- 九度OJ 1127:简单密码 (翻译)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1218 解决:721 题目描述: Julius Caesar曾经使用过一种很简单的密码. 对于明文中的每个字符,将它用它字母表中后5位对应的 ...
- Performance Tuning Using Linux Process Management Commands
[root@bigdata-server-02 /]# ps --help all Usage: ps [options] Basic options: -A, -e all processes -a ...
- 项目中一个普通的Java类如何获取serviceimpl实现类(二)
HbOnLineConfigServiceImpl hbOnlineService=(HbOnLineConfigServiceImpl) WebContextFactoryUtil.getBean( ...
- 【C++基础学习】类型声明
1.初始化 在C++中,初始化与赋值操作是完全不同的两个操作.初始化不是赋值,初始化的含义是创建变量时赋予其一个初始值,而赋值的含义是把对象的当前值擦除,而以一个新值来代替. 初始化的方式有: 1 i ...
- 有关Option.inSamplSize 和 Compress 图片压缩
1.图片占用内存:占用的内存 = 图片长度 * 图片宽度 * 单位像素占用的字节数 注: 图片长度和图片宽度就是图片在行列上的像素数量. 图片格式: ALPHA_8:表示8位Alpha位图,即A=8, ...