hdu4336 Card Collector 容斥原理
In your childhood, do you crazy for collecting the beautiful cards in the snacks? They said that, for example, if you collect all the 108 people in the famous novel Water Margin, you will win an amazing award.
As a smart boy, you notice that to win the award, you must buy much more snacks than it seems to be. To convince your friends not to waste money any more, you should find the expected number of snacks one should buy to collect a full suit of cards.
容斥原理
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std; double p[]; int main(){
int n;
while(scanf("%d",&n)!=EOF){
for(int i=;i<=n;++i)scanf("%lf",&p[i]);
double ans=;
for(int i=;i<(<<n);++i){
int bit=;
double tmp=;
for(int j=;j<=n;++j){
if(i&(<<(j-))){
bit++;
tmp+=p[j];
}
}
if(bit%)ans+=1.0/tmp;
else ans-=1.0/tmp;
}
printf("%.10lf\n",ans);
}
return ;
}
hdu4336 Card Collector 容斥原理的更多相关文章
- hdu4336 Card Collector 状态压缩dp
Card Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- [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(或容斥原理?)
题意: 买东西集齐全套卡片赢大奖.每个包装袋里面有一张卡片或者没有. 已知每种卡片出现的概率 p[i],以及所有的卡片种类的数量 n(1<=n<=20). 问集齐卡片需要买东西的数量的期望 ...
- hdu 4336 Card Collector 容斥原理
读完题目就知道要使用容斥原理做! 下面用的是二进制实现的容斥原理,详见:http://www.cnblogs.com/xin-hua/p/3213050.html 代码如下: #include< ...
- HDU-4336 Card Collector 概率DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意:买食品收集n个卡片,每个卡片的概率分别是pi,且Σp[i]<=1,求收集n个卡片需要 ...
- hdu4336 Card Collector
Problem Description In your childhood, do you crazy for collecting the beautiful cards in the snacks ...
- hdu4336 Card Collector 【最值反演】
题目链接 hdu4336 题解 最值反演 也叫做\(min-max\)容斥,在计算期望时有奇效 \[max\{S\} = \sum\limits_{T \in S} (-1)^{|T| + 1}min ...
- hdu4336 Card Collector(概率DP,状态压缩)
In your childhood, do you crazy for collecting the beautiful cards in the snacks? They said that, fo ...
- hdu4336 Card Collector MinMax 容斥
题目传送门 https://vjudge.net/problem/HDU-4336 http://acm.hdu.edu.cn/showproblem.php?pid=4336 题解 minmax 容 ...
随机推荐
- R语言常用操作
1 取整运算 在编程实现的时候有时会碰到对数值取整的需求,而取整的方式却多种多样,依赖于具体问题,不过在R中已经配备了种类齐全的相关函数,主要包括以下五种: floor():向下取整: ceiling ...
- C#通过shell32获取文件详细备注信息
1.从系统Window/System32文件夹中Copy出 Shell32.dll Com组件 将Shell32.dll文件引用到项目中,并设置“嵌入互操作类型”为false http://blog. ...
- LeetCode 回溯法 别人的小结 八皇后 递归
#include <iostream> #include <algorithm> #include <iterator> #include <vector&g ...
- 根据访问ip的地区跳转到指定地址
<script type="text/javascript" src="http://ip.ws.126.net/ipquery"></scr ...
- lxml简单用法 解析网页
import requests s=requests.Session() re=s.get(lgurl,headers=headers) #此处s可以直接换成requests the_page=re ...
- CKEditor编辑器的使用
<div class="form-group" id="infolink-edier-div"> <label for="" ...
- String转换成Boolean类型
Boolean.valueOf()方法: public static Boolean valueOf(String s) { return toBoolean(s) ? TRUE : FALSE; } ...
- IDEA中自动生成serialVersionUID
File >> Setting >> Inspections >> serializable 勾选上后,光标放在实现Serializable接口的类名上 ...
- jvm内存配置参数
请看下面题目: 对于jvm内存配置参数: -Xmx10240m -Xms10240m -Xmn5120m -XXSurvivorRatio=3 其最小内存值和Survior区总大小分别是: a. 51 ...
- C#窗体的浮动及隐藏
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...