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. Java 判断多级路径是否存在,不存在就创建

    第一种方案: /** * 是否创建目录 * @param path * @return */ public boolean isexitsPath(String path)throws Interru ...

  2. 工作随记 warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds

    错误信息:F:\BUILD\IDS7020\trunk\manage_src\dev\java_src\tds7030-web\Ant\build.xml:344: warning: 'include ...

  3. VC实现URL编解码器

    //变化UTF8为了中国 void UTF8ToGB(CString& szstr) { WCHAR* strSrc; TCHAR* szRes; int i = MultiByteToWid ...

  4. Blog 转移

    Blog 转移至 http://blog.rapcoder.com CSDN :  http://blog.csdn.net/a542551042 欢迎一起交流 学习 ,谢谢!!!

  5. 减少可执行程序size的三个常用软件

    减少可执行程序size的三个常用软件 linux下面,直接用strip 这个命令 #:strip xxx 可以去掉编译调试信息和各种符号表,能够大大减小可执行程序size windows下面这种exe ...

  6. hihoCoder 1014trie树(字典树)

    hihoCoder 1014 题目提示已经很清楚了~ 贴代码…… #include <iostream> #include <cstdio> #include <cstr ...

  7. Java 异常解决之java.lang.IllegalArgumentException: Comparison method violates its general contract!

    Java 异常解决 在你的代码前加一句 System.setProperty("java.util.Arrays.useLegacyMergeSort", "true&q ...

  8. EasyUI - DataGrid 组建 - [ 样式功能 ]

    效果显示: 同上次博文效果. html代码: 同上次博文代码. js代码: align: 'center',//标题和内容居中 resizable: false,//不允许改变大小 //hidden: ...

  9. C#、WinForm、ASP.NET - SQLHelper.cs

    SQLHelper.cs using System; using System.Data; using System.Configuration; using System.Data.SqlClien ...

  10. 自己用h5写的转盘。写贴上来吧。

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...