Card Collector

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d
& %I64u

Appoint description: 
System Crawler  (2014-10-23)

Description

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.
 

Input

The first line of each test case contains one integer N (1 <= N <= 20), indicating the number of different cards you need the collect. The second line contains N numbers p1, p2, ..., pN, (p1 + p2 + ... + pN <= 1), indicating the possibility
of each card to appear in a bag of snacks. 



Note there is at most one card in a bag of snacks. And it is possible that there is nothing in the bag.
 

Output

Output one number for each test case, indicating the expected number of bags to buy to collect all the N different cards. 



You will get accepted if the difference between your answer and the standard answer is no more that 10^-4.
 

Sample Input

1
0.1
2
0.1 0.4
 

Sample Output

10.000
10.500
 

/*************************************************************************
> File Name: t.cpp
> Author: acvcla
> Mail: acvcla@gmail.com
> Created Time: 2014年10月21日 星期二 21时33分55秒
************************************************************************/
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<cstring>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<cstdlib>
#include<ctime>
#include<set>
#include<math.h>
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 10;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
double dp[1<<20],p[1<<20],A[200];
void Init(int n){
memset(p,0,sizeof p);
memset(dp,0,sizeof dp);
for(int i=(1<<n)-1;i>0;i--){
double t=0;
for(int j=0;j<n;j++)if(1<<j&i)
{
p[i]+=A[j];
}
}
}
int n;
int main(int argc, char const *argv[])
{
while(~scanf("%d",&n)){
double s=1;
for(int i=0;i<n;i++){
scanf("%lf",A+i);
s-=A[i];
}
Init(n);
for(int i=(1<<n)-2;i>=0;i--){
double t=0;
double pi=p[i]+s;
for(int j=0;j<n;j++){
if((1<<j)&i)continue;
else{
int temp=i|(1<<j);
t+=dp[temp]*A[j];
}
}
dp[i]=(t+1)/(1-pi);
}
printf("%.4f\n",dp[0]);
}
return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

可能性dp+减少国家HDU4336的更多相关文章

  1. POJ 2411 Mondriaan&#39;s Dream (dp + 减少国家)

    链接:http://poj.org/problem?id=2411 题意:题目描写叙述:用1*2 的矩形通过组合拼成大矩形.求拼成指定的大矩形有几种拼法. 參考博客:http://blog.csdn. ...

  2. [AC自己主动机+可能性dp] hdu 3689 Infinite monkey theorem

    意甲冠军: 给n快报,和m频率. 然后进入n字母出现的概率 然后给目标字符串str 然后问m概率倍的目标字符串是敲数量. 思维: AC自己主动机+可能性dp简单的问题. 首先建立trie图,然后就是状 ...

  3. [ACM] hdu 5045 Contest (减少国家Dp)

    Contest Problem Description In the ACM International Collegiate Programming Contest, each team consi ...

  4. poj - 1170 - Shopping Offers(减少国家dp)

    意甲冠军:b(0 <= b <= 5)商品的种类,每个人都有一个标签c(1 <= c <= 999),有需要购买若干k(1 <= k <=5),有一个单价p(1 & ...

  5. Light OJ 1406 Assassin`s Creed 减少国家DP+支撑点甚至通缩+最小路径覆盖

    标题来源:problem=1406">Light OJ 1406 Assassin`s Creed 意甲冠军:向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路: ...

  6. HDU 4433 locker 2012 Asia Tianjin Regional Contest 减少国家DP

    意甲冠军:给定的长度可达1000数的顺序,图像password像锁.可以上下滑动,同时会0-9周期. 每个操作.最多三个数字连续操作.现在给出的起始序列和靶序列,获得操作的最小数量,从起始序列与靶序列 ...

  7. Chapter06-Phylogenetic Trees Inherited(POJ 2414)(减少国家DP)

    Phylogenetic Trees Inherited Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 480 Accepted ...

  8. poj 1185 火炮 (减少国家DP)

    火炮 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 19690   Accepted: 7602 Description 司 ...

  9. hdu 4778 Rabbit Kingdom(减少国家)

    题目链接:hdu 4778 Rabbit Kingdom 题目大意:Alice和Bob玩游戏,有一个炉子.能够将S个同样颜色的宝石换成一个魔法石.如今有B个包,每一个包里有若干个宝石,给出宝石的颜色. ...

随机推荐

  1. QTP实践总结

    QTP实践总结 查询数据库修改freq 1.Testcasetable创建查询select * from testcasetable order by fseq desc 2.设计表-选项-修改自动递 ...

  2. android的fragment基本介绍

    可以分为下面的几部分: 使用支持库 创建一个Fragment 创建一个动态UI 多个Fragment之间的通信 1.使用支持库 如果您的应用需要运行在3.0及以上的版本,可以忽略这部分内容. 如果您的 ...

  3. python读取文件内容方法

    1) readline 每次读一行,返回序列 2) readlines 一次全部读出,返回序列 3) numpy 的genfromtxt,返回为np的矩阵格式 import numpy as np f ...

  4. 【C# -- OpenCV】Emgu CV 第一个实例

    原文 [C# -- OpenCV]Emgu CV 第一个实例 Emgu CV下载地址 http://sourceforge.net/projects/emgucv/files/ 找最新的下就行了,傻瓜 ...

  5. HDU 4160 Dolls (最小路径覆盖=顶点数-最大匹配数)

    Dolls Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...

  6. highcharts dynamic change line color

    mouseOut: function(){ this.series.graph.attr({"stroke","#ccc"}) }

  7. 从 Racket 入门函数式编程

    一直想学学LISP,今天总算开了个头.如今学习LISP不是为了立就可以以用于实际项目的应用,而是为了学习一下函数式的思维方式,可以更加深入的了解计算的本质,可以更好的用C++, Java, Pytho ...

  8. GridView点击空白地方事件扩展

    我们通常在ListView或者GridView响应点击Item事件,但很多时候我们同样也 希望监听到点击空白区域的事件来做更多的处理.本文以GridView为例给出一个实现 的方法,扩展GridVie ...

  9. oracle逻辑导入小错:提示无法创建日志提示

    ***********************************************声明*************************************************** ...

  10. /bin/bash^M: 坏的解释器: 没有那个文件或目录

    在Linux下编译cocos2d-x运行脚本的时候出现”/bin/bash^M: 坏的解释器: 没有那个文件或目录“这样的错误如下图. 解决方法: 使用在终端输入sed -i 's/\r$//' ma ...