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 ...
随机推荐
- Uploadify上传大文件
一丶参考地址 <script type="text/javascript"> var auth = "@(Request.Cookies[FormsAuthe ...
- Humidex POJ - 3299 (数学)
题目大意 给定你三个变量中的两个输出剩下的那一个 题解 没有什么,就是把公式推出来即可,完全的数学题 代码 #include <iostream> #include <cmath&g ...
- Linux 下 Bash 脚本对拍
背会... #!/bin/bash i= while true ;do ./maker > data.in ./a <data.in> data.out ./b <data.i ...
- 洛谷 3398 仓鼠找sugar 【模板】判断树上两链有交
[题解] 题意就是判断树上两条链是否有交.口诀是“判有交,此链有彼祖”.即其中一条链的端点的Lca在另一条链上. 我们设两条链的端点的Lca中深度较大的为L2,对L2与另一条链的两个端点分别求Lca, ...
- JavaSE 学习笔记之新特性之泛型(二十)
泛型:jdk1.5版本以后出现的一个安全机制.表现格式:< > 好处: 1:将运行时期的问题ClassCastException问题转换成了编译失败,体现在编译时期,程序员就可以解决问题. ...
- UVALive 6510 Stickers
Stickers Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVALive. Original ...
- FFT模板(From MG)
#include<cstdio> #include<cmath> #include<algorithm> using namespace std; struct c ...
- Extended symmetrical multiprocessor architecture
An architecture for an extended multiprocessor (XMP) computer system is provided. The XMP computer s ...
- Win32编程API 基础篇 -- 3.消息处理 根据英文教程翻译
消息处理 例子:窗口点击 好的,现在我们已经得到一个窗口了,但我们什么也做不了除了DefWindowProc()允许窗口大小被调整,最大最小化等...这不是很激动人心啊 在接下来的一小节中我将向你展示 ...
- Asp.Net页面生命周期[转]
一.什么是Asp.Net页面生命周期 当我们在浏览器地址栏中输入网址,回车查看页面时,这时会向服务器端(IIS)发送一个request请求,服务器就会判断发送过来的请求页面, 完全识别 HTTP 页 ...