概率DP/数学期望/状压DP/容斥原理

  kuangbin总结中的第14题

  好神奇的做法……题解看kuangbin的代码好了……

 //HDOJ 4336
#include<cstdio>
#define rep(i,n) for(int i=0;i<n;++i)
#define F(i,j,n) for(int i=j;i<=n;++i)
#define D(i,j,n) for(int i=j;i>=n;--i)
const int N=; double p[N],f[<<N];
int main(){
int n;
while(scanf("%d",&n)!=EOF){
double tt=0.0;
rep(i,n){
scanf("%lf",&p[i]);
tt+=p[i];
}
tt=-tt;
f[(<<n)-]=;
D(i,(<<n)-,){
double x=,sum=1.0;
rep(j,n)
if(i & (<<j))x+=p[j];
else sum+=p[j]*f[i|(<<j)];
f[i]=sum/(-tt-x);
}
printf("%.5lf\n",f[]);
}
return ;
}

(概率DP)

 //HDOJ 4336
#include<cstdio>
#define rep(i,n) for(int i=0;i<n;++i)
#define F(i,j,n) for(int i=j;i<=n;++i) double p[];
int main(){
int n;
while(scanf("%d",&n)!=EOF){
rep(i,n) scanf("%lf",&p[i]);
double ans=;
for(int i=;i<(<<n);++i){
int cnt=; double sum=;
rep(j,n) if(i&(<<j)){
sum+=p[j];
cnt++;
}
if (cnt&) ans+=1.0/sum;
else ans-=1.0/sum;
}
printf("%.5lf\n",ans);
}
return ;
}

(容斥原理)

【HDOJ】【4336】Card Collector的更多相关文章

  1. HDU 4336:Card Collector(容斥原理)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=4336 Card Collector Special Judge Problem Descriptio ...

  2. 【HDOJ图论题集】【转】

    =============================以下是最小生成树+并查集====================================== [HDU] How Many Table ...

  3. 【集训笔记】博弈论相关知识【HDOJ 1850【HDOJ2147

    以下资料来自:http://blog.csdn.net/Dinosoft/article/details/6795700 http://qianmacao.blog.163.com/blog/stat ...

  4. HDU - 4336:Card Collector(min-max容斥求期望)

    In your childhood, do you crazy for collecting the beautiful cards in the snacks? They said that, fo ...

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

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

  6. 【HDU4336】Card Collector(Min-Max容斥)

    [HDU4336]Card Collector(Min-Max容斥) 题面 Vjudge 题解 原来似乎写过一种状压的做法,然后空间复杂度很不优秀. 今天来补一种神奇的方法. 给定集合\(S\),设\ ...

  7. 【HDU4336】Card Collector (动态规划,数学期望)

    [HDU4336]Card Collector (动态规划,数学期望) 题面 Vjudge 题解 设\(f[i]\)表示状态\(i\)到达目标状态的期望 \(f[i]=(\sum f[j]*p[j]+ ...

  8. 【BZOJ4391】[Usaco2015 dec]High Card Low Card(贪心)

    [BZOJ4391][Usaco2015 dec]High Card Low Card(贪心) 题面 BZOJ 题解 预处理前缀后缀的结果,中间找个地方合并就好了. #include<iostr ...

  9. 【HDOJ 5379】 Mahjong tree

    [HDOJ 5379] Mahjong tree 往一颗树上标号 要求同一父亲节点的节点们标号连续 同一子树的节点们标号连续 问一共同拥有几种标法 画了一画 发现标号有二叉树的感觉 初始标号1~n 根 ...

  10. HDOJ 1238 Substrings 【最长公共子串】

    HDOJ 1238 Substrings [最长公共子串] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...

随机推荐

  1. AMQ学习笔记 - 18. 持久化的测试

    概述 对持久化的有效性进行测试. 测试实例 测试实例 结果预测 持久化递送 重启ActiveMQ后,消息还在队列中 非持久化递送 重启ActiveMQ后,消息不在队列中 demo设计 jms-prod ...

  2. (转)每天一个linux命令(46):vmstat命令

    vmstat是Virtual Meomory Statistics(虚拟内存统计)的缩写,可对操作系统的虚拟内存.进程.CPU活动进行监控.他是对系统的整体情况进行统计,不足之处是无法对某个进程进行深 ...

  3. 10+ powerful debugging tricks with Visual Studio

    10+ powerful debugging tricks with Visual Studio Original link : http://www.codeproject.com/Articles ...

  4. (转)HTML5游戏如何挣钱?2条经验让你每款赚3万刀

    原文作者:Alexander Krug,是世界上最大的HTML5游戏平台的运营商SOFTGAMES的CEO. 现今苹果App Store当中的应用数量可以以海量来形容,最新发布的应用对排行榜的冲击力也 ...

  5. HTML5-Video & Audio

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  6. js实现模拟自动点击按钮,并且在10秒倒计时之后疯狂点击

    需求来自于csdn问答,可以利用这个原理做秒杀抢单外挂. 代码示例如下: <html> <head> <meta charset="utf-8"/&g ...

  7. 免费GIT托管

    http://www.gitcentral.com http://www.projectlocker.com http://gitfarm.appspot.com http://code.google ...

  8. php获取服务器时间的代码

    php获取服务器时间的代码. 用php的date函数即可来获取服务器上的时间:  <?php //将时区设置为中国 date_default_timezone_set("PRC&quo ...

  9. ActiveMQ.xml文件的主要配置

    ActiveMQ.xml文件默认位置位于 activemq/conf/目录下,主要的配置及解析如下:<beans xmlns="http://www.springframework.o ...

  10. Activity的Launch mode详解 singleTask正解

    Activity有四种加载模式:standard(默认), singleTop, singleTask和 singleInstance.以下逐一举例说明他们的区别: standard:Activity ...