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 ...
随机推荐
- python(23)- 面向对象简单介绍
面向概述 面向过程:根据业务逻辑从上到下写垒代码 面向过程的设计的核心是过程,过程即解决问题的步骤, 面向过程的设计就好比精心设计好一条流水线,考虑周全什么时候处理什么东西 优点:极大降低了程序的复杂 ...
- 关于Swiper(概念)
Swiper 是一款免费以及轻量级的移动设备触控滑块的js框架,使用硬件加速过渡(如果该设备支持的话). 主要使用于移动端的网站.移动web apps,native apps和hybrid apps. ...
- surface 通过U盘 镜像恢复系统
1. 在恢复之前首先要解锁bitlocker(如果你的surface没有加锁就不需要这个步骤) 在另一台电脑上登录bitlocker锁绑定的微软账号,查询密钥,在需要的地方输入这个密钥(不经过这个操作 ...
- centos7下MySQL的配置
1. 下载mysql的repo源 wget http:.noarch.rpm 2. 安装mysql-community-release-el7-5.noarch.rpm包 rpm .noarch.rp ...
- python--面向对象组合
面向对象的命名空间 类中的方法 类中的静态属性 对象的属性类的组合应用 面向对象的命名空间 class A: country='中国' a=A() a.name='alex' print(a. ...
- JAVA sql语句动态参数问题
对sql语句设置动态参数 import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.DriverMan ...
- 程序猿的量化交易之路(27)--Cointrader之PriceData价格数据(14)
转载须注明出处:http://blog.csdn.net/minimicall?viewmode=contents,http://cloudtrade.top/ PriceData:价格数据.价格数据 ...
- mysql 中的增改查删(CRUD)
增改查删可以用CURD来表示 增加:create 修改:update 查找:read 删除:delete 增加create : insert +表名+values+(信息): in ...
- memcmp和strcmp的返回值
注意,无论是内存比较还是字符串比较,这两个函数的返回值的意义是一样的. 如果相同,返回0 如果前面大于后面,返回大于0 如果前面小于后面,返回小于0 一定要注意,相同的时候是0,不是true.
- Part of defining a topology is specifying for each bolt which streams it should receive as input
http://storm.apache.org/ [doing for realtime processing what Hadoop did for batch processing ] Apach ...