可能性dp+减少国家HDU4336
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d
& %I64u
cid=60444#status//K/0" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" style="display:inline-block; position:relative; padding:0px; margin-right:0.1em; vertical-align:middle; overflow:visible; text-decoration:none; font-family:Verdana,Arial,sans-serif; font-size:1em; border:1px solid rgb(211,211,211); color:rgb(85,85,85)">Status
Practicepid=4336" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" style="display:inline-block; position:relative; padding:0px; margin-right:0.1em; vertical-align:middle; overflow:visible; text-decoration:none; font-family:Verdana,Arial,sans-serif; font-size:1em; border:1px solid rgb(211,211,211); color:rgb(85,85,85)">HDU
4336
System Crawler (2014-10-23)
Description
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
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
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的更多相关文章
- POJ 2411 Mondriaan's Dream (dp + 减少国家)
链接:http://poj.org/problem?id=2411 题意:题目描写叙述:用1*2 的矩形通过组合拼成大矩形.求拼成指定的大矩形有几种拼法. 參考博客:http://blog.csdn. ...
- [AC自己主动机+可能性dp] hdu 3689 Infinite monkey theorem
意甲冠军: 给n快报,和m频率. 然后进入n字母出现的概率 然后给目标字符串str 然后问m概率倍的目标字符串是敲数量. 思维: AC自己主动机+可能性dp简单的问题. 首先建立trie图,然后就是状 ...
- [ACM] hdu 5045 Contest (减少国家Dp)
Contest Problem Description In the ACM International Collegiate Programming Contest, each team consi ...
- poj - 1170 - Shopping Offers(减少国家dp)
意甲冠军:b(0 <= b <= 5)商品的种类,每个人都有一个标签c(1 <= c <= 999),有需要购买若干k(1 <= k <=5),有一个单价p(1 & ...
- Light OJ 1406 Assassin`s Creed 减少国家DP+支撑点甚至通缩+最小路径覆盖
标题来源:problem=1406">Light OJ 1406 Assassin`s Creed 意甲冠军:向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路: ...
- HDU 4433 locker 2012 Asia Tianjin Regional Contest 减少国家DP
意甲冠军:给定的长度可达1000数的顺序,图像password像锁.可以上下滑动,同时会0-9周期. 每个操作.最多三个数字连续操作.现在给出的起始序列和靶序列,获得操作的最小数量,从起始序列与靶序列 ...
- Chapter06-Phylogenetic Trees Inherited(POJ 2414)(减少国家DP)
Phylogenetic Trees Inherited Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 480 Accepted ...
- poj 1185 火炮 (减少国家DP)
火炮 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 19690 Accepted: 7602 Description 司 ...
- hdu 4778 Rabbit Kingdom(减少国家)
题目链接:hdu 4778 Rabbit Kingdom 题目大意:Alice和Bob玩游戏,有一个炉子.能够将S个同样颜色的宝石换成一个魔法石.如今有B个包,每一个包里有若干个宝石,给出宝石的颜色. ...
随机推荐
- CMake使用之一
概述 CMake是一个比make更高级的编译配置工具,它可以根据不同平台.不同的编译器,生成相应的Makefile或者vcproj项目. 通过编写CMakeLists.txt,可以控制生成的Makef ...
- Java网络编程:利用apache的HttpClient包进行http操作
本文介绍如何利用apache的HttpClient包进行http操作,包括get操作和post操作. 一.下面的代码是对HttpClient包的封装,以便于更好的编写应用代码. import java ...
- python去掉html标签
s = '<SPAN style="FONT- SIZE: 9pt">开始1~3<SPAN lang=EN-US>& lt;?xml:namespa ...
- .NET支持上下左右移动操作
效果如下图: 代码如下: public partial class ShowSet : System.Web.UI.Page { Hashtable resources = EquStatusSear ...
- hdu 4614 Vases and Flowers (二分 线段树)
题目大意:爱丽丝有N个花瓶,每个花瓶最多放一朵花.然后又如下两个操作. 1:A B 从第A个花瓶开始,往后依次插B朵花,直到不能插为止.如果一朵花都不能插入就输出“can.....”,否则输出第 ...
- android开发隐藏了actionbar仍然短暂闪现的解决方法
有时候我们在代码里隐藏了actionbar,在打开应用时,仍然短暂闪现下actionbar,用户体验很不好. 最简单的方法是 在AndroidManifest.xml中设置主题中配置不显示titl ...
- Ch04 充满动作的控制器
4.1 考察控制器和动作 4.1.1 IController与控制器基类 4.1.2 如何形成动作方法 4.2 哪些应该放在动作方法中 4.2.1 手动映射视图模型 4.2.2 输入验证 ...
- QUrl不同版本之间的坑
在项目中使用了native application + html的方式构建界面. 之前在4.8.4用QUrl直接加载相对路径一点问题都没有.但是切换到5.1编译之后却发现本地的html文件全部没有加载 ...
- Swift - 判断设备方向(或监听设备方向的改变)
通过UIDevice.currentDevice()来获取设备,可以取得设备当前的方向. 同时,我们可以添加一个通知来监听设备方向的变化,这样在开发中可以对不同的方向定制不同的排版布局界面. 下面通过 ...
- linux 下启动jar小程序
下面是我的三个可运行jar程序 1.启动 采集话单文件应用程序 nohup java -jar gather.jar > logs/gather/console.out & 2.启动 ...