题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4336

题意简单,直接用容斥原理即可

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
#include <sstream>
using namespace std; typedef long long LL;
const int N=22;
const LL II=100000000;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0); double p[N]; int main()
{
int i,j,n,T,ca=0;
while(cin>>n)
{
double xh=0,sum=0;
for(i=1;i<=n;i++)
scanf("%lf",&p[i]);
for(i=1;i<(1<<n);i++)
{
sum=0;
int odd=0;
for(j=0;j<n;j++)
{
if((1<<j)&i)
{
odd++;
sum+=p[j+1];
}
}
if(odd&1) // 加奇减偶
xh+=1/sum;
else
xh-=1/sum;
}
printf("%.6f\n",xh);
}
return 0;
}
/*
3
0.1 0.2 0.3
*/

HDU 4336 Card Collector 数学期望(容斥原理)的更多相关文章

  1. HDU 4336 Card Collector:期望dp + 状压

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意: 一共有n种卡片.每买一袋零食,有可能赠送一张卡片,也可能没有. 每一种卡片赠送的概率为p ...

  2. HDU 4336 Card Collector 期望dp+状压

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4336 Card Collector Time Limit: 2000/1000 MS (Java/O ...

  3. hdu 4336 Card Collector (概率dp+位运算 求期望)

    题目链接 Card Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  4. HDU 4336 Card Collector(动态规划-概率DP)

    Card Collector Problem Description In your childhood, do you crazy for collecting the beautiful card ...

  5. HDU 4336——Card Collector——————【概率dp】

    Card Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  6. HDU 4336 Card Collector:状压 + 期望dp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意: 有n种卡片(n <= 20). 对于每一包方便面,里面有卡片i的概率为p[i],可 ...

  7. HDU 4336 Card Collector (期望DP+状态压缩 或者 状态压缩+容斥)

    题意:有N(1<=N<=20)张卡片,每包中含有这些卡片的概率,每包至多一张卡片,可能没有卡片.求需要买多少包才能拿到所以的N张卡片,求次数的期望. 析:期望DP,是很容易看出来的,然后由 ...

  8. hdu 4336 Card Collector(期望 dp 状态压缩)

    Problem Description In your childhood, people in the famous novel Water Margin, you will win an amaz ...

  9. hdu 4336 Card Collector 容斥原理

    读完题目就知道要使用容斥原理做! 下面用的是二进制实现的容斥原理,详见:http://www.cnblogs.com/xin-hua/p/3213050.html 代码如下: #include< ...

随机推荐

  1. C语言练习代码

    1.运用for循环根据输入的金字塔层数,输出金字塔 eg: #include <stdio.h>int main(void){ int i,j,num; printf("请输入三 ...

  2. [转]linux之more命令

    转自:http://www.cnblogs.com/peida/archive/2012/11/02/2750588.html more命令,功能类似 cat ,cat命令是整个文件的内容从上到下显示 ...

  3. 【LeetCode】242 - Valid Anagram

    Given two strings s and t, write a function to determine if t is an anagram of s. For example,s = &q ...

  4. STL map 用法

    首先make_pair Pairs C++标准程序库中凡是"必须返回两个值"的函数, 也都会利用pair对象  class pair可以将两个值视为一个单元.容器类别map和mul ...

  5. O2O在线教育平台策划方案

    一.情景需求痛点: 学生: 1.除了上课上课,就是作业作业,学习太枯燥不好玩怎么办?——我就是想要玩玩玩! 2.第二天要交作业,老师不在,在家作业不懂怎么办?——我想要随身老师! 3.噢耶,周末不用上 ...

  6. searchBar 隐藏

    searchBar 隐藏 CGRect newBounds = self.tableView.bounds; newBounds.origin.y = newBounds.origin.y + _he ...

  7. 指令式Callback,函数式Promise:对node.js的一声叹息

    原文:Callbacks are imperative, promises are functional: Node's biggest missed opportunity promises 天生就 ...

  8. xml velocity模板

    . <?xml version="1.0" encoding="GBK"?> <PACKET type="REQUEST" ...

  9. 常见mongo命令

    @(编程) 查询 db.getCollection('SalaryEntity').find({"Month" : "201601"}) db.getColle ...

  10. 关于datatable的一些操作以及使用adapter对数据的操作

    private void updateToolStripMenuItem_Click(object sender, EventArgs e) {//将数据更新回数据库 //获取源数据 DataTabl ...