HDU4336:Card Collector
题意
有n张卡片,每一次 有pi的概率买到第i张卡。求买到所有卡的期望购买次数。
n<=20
解析
Solution 1:大力状压(就是步数除以方案数)
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#define ll long long
#define re register
#define il inline
#define fp(i,a,b) for(re int i=a;i<=b;i++)
#define fq(i,a,b) for(re int i=a;i>=b;i--)
using namespace std;
double a[22],ans;double dp[1<<21];
int T,n;
int main()
{
while(scanf("%d",&n)!=EOF)
{
fp(i,0,n-1) scanf("%lf",&a[i]);
dp[(1<<n)-1]=0;
fq(i,(1<<n)-2,0)
{
re double sum=1,x=0;
fp(j,0,n-1)
{
if(!(i&(1<<j)))
{
x+=a[j];
sum+=dp[i|(1<<j)]*a[j];
}
dp[i]=sum/x;
}
}
printf("%.4lf\n",dp[0]);
}
return 0;
}
Solution 2:min_max容斥
不知道有什么用。。。。
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#define ll long long
#define re register
#define il inline
#define fp(i,a,b) for(re int i=a;i<=b;i++)
#define fq(i,a,b) for(re int i=a;i>=b;i--)
using namespace std;
double a[22],ans;//double dp[1<<21];
int T,n;
il void dfs(re int x,re double s,re int f)
{
if(x>n) {if(s>1e-9) ans+=f*1/s;return;}
dfs(x+1,s+a[x],-f);dfs(x+1,s,f);
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
fp(i,1,n) scanf("%lf",&a[i]);
ans=0;dfs(1,0,-1);
printf("%.4lf\n",ans);
}
return 0;
}
HDU4336:Card Collector的更多相关文章
- HDU4336:Card Collector(min-max容斥)
题面 传送门 Sol 方法一 直接状压就好了 # include <bits/stdc++.h> # define RG register # define IL inline # def ...
- 【HDU4336】Card Collector(Min-Max容斥)
[HDU4336]Card Collector(Min-Max容斥) 题面 Vjudge 题解 原来似乎写过一种状压的做法,然后空间复杂度很不优秀. 今天来补一种神奇的方法. 给定集合\(S\),设\ ...
- 【HDU4336】Card Collector (动态规划,数学期望)
[HDU4336]Card Collector (动态规划,数学期望) 题面 Vjudge 题解 设\(f[i]\)表示状态\(i\)到达目标状态的期望 \(f[i]=(\sum f[j]*p[j]+ ...
- HDU 4336:Card Collector(容斥原理)
http://acm.split.hdu.edu.cn/showproblem.php?pid=4336 Card Collector Special Judge Problem Descriptio ...
- HDU - 4336:Card Collector(min-max容斥求期望)
In your childhood, do you crazy for collecting the beautiful cards in the snacks? They said that, fo ...
- [HDU4336]Card Collector(min-max容斥,最值反演)
Card Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu4336 Card Collector 状态压缩dp
Card Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- Card Collector(HDU 4336)
Card Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU 4336 Card Collector(动态规划-概率DP)
Card Collector Problem Description In your childhood, do you crazy for collecting the beautiful card ...
随机推荐
- Linux系统硬软信息
系统硬软信息 //获取根用户权限su //升级内核 yum update kernel
- linux mysql设置远程访问
>mysql -u root -p 选择进入mysql数据库use `mysql`; 查看所有存在的账号和地址.SELECT `Host`,`User` FROM `user`; 现在决定让ro ...
- SIGFPE能处理上下溢吗?
SIGFPE可以报告算术异常.包括上下溢.除零等. C标准库说: 各种实现报告的异常类型区别也很大,但几乎没有实现会报告整型溢出. 真的吗?我测试了一下,发现在GCC上,整型.浮点上下溢都不会报告,但 ...
- Codeforces 280C - Game on Tree
传送门:280C - Game on Tree 不知道期望是啥的请自行Baidu或Google,(溜了 题目大意,有一棵有根树,每次随机选择一个节点,将这个节点和它的子树删除,问将整棵树删除的期望次数 ...
- FTP配置
常用的匿名FTP配置项 anonymous_enable=YES 是否允许匿名用户访问 anon_umask=022 匿名用户所上传文件的权限 ...
- linux strings-在对象文件或二进制文件中查找可打印的字符串
推荐:更多Linux 文件查找和比较 命令关注:linux命令大全 strings命令在对象文件或二进制文件中查找可打印的字符串.字符串是4个或更多可打印字符的任意序列,以换行符或空字符结束. str ...
- Volume 6. Mathematical Concepts and Methods
138 - Street Numbers #include <stdio.h> //(2n+1)^2 - 8m^2 = 1,佩尔函数,或者打表 int main() { ; , xi = ...
- airfoil polar data during post stall stages (high AOA)
airfoil polar data during post stall stages (high AOA) Table of Contents 1. airfoil polar during pos ...
- PAT 1137 Final Grading
For a student taking the online course "Data Structures" on China University MOOC (http:// ...
- HDU 1274 递归拼接字符串
题目大意: 根据所给的数字,表示其相连的字符的输出个数,或是下一个括号中的所有字符的输出个数 每一个相互对应的 '(' 和 ')' 中的所有字母均作为一组数据处理 在每一次dfs过程中都处理好这样一个 ...