[CF442B] Andrey and Problem (概率dp)
题目链接:http://codeforces.com/problemset/problem/442/B
题目大意:有n个人,第i个人出一道题的概率是pi,现在选出一个子集,使得这些人恰好出一个题的概率最大。问最大概率。
可以仿照背包问题来做,即每个人可问可不问。
f[i][j]代表从前i个人里问j个人所获得1个题的最大概率。
f[i][j] = max{ f[i-1][j], f[i-1][j-1]*(1-p[i])+z[i-1][j-1]*p[i] };
z[i][j]为从前i个人里问j个人所获得1个题的最大概率对应的一个题也出不出来的概率。
转移见代码
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <cmath>
#include <numeric>
#include <iterator>
#include <iostream>
#include <cstdlib>
#include <functional>
#include <queue>
#include <stack>
#include <string>
#include <cctype>
using namespace std;
#define PB push_back
#define MP make_pair
#define SZ size()
#define ST begin()
#define ED end()
#define CLR clear()
#define ZERO(x) memset((x),0,sizeof(x))
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
const double EPS = 1e-; int n;
double f[][],p[],z[][]; int main(){
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%lf",&p[i]);
for(int i=;i<;i++) z[][i] = z[i][] = 1.0;
for(int i=;i<=n;i++){
for(int j=;j<=i;j++){
// printf("i=%d,j=%d\n",i,j);
// printf("f[i-1][j]=%f,f[i-1][j-1]*(1-p[i])+z[i-1][j-1]*p[i]=%f\n",f[i-1][j],f[i-1][j-1]*(1-p[i])+z[i-1][j-1]*p[i]);
if( f[i-][j]<f[i-][j-]*(-p[i])+z[i-][j-]*p[i] ){
f[i][j] = f[i-][j-]*(-p[i])+z[i-][j-]*p[i];
z[i][j] = z[i-][j-]*(-p[i]);
} else {
f[i][j] = f[i-][j];
z[i][j] = z[i-][j];
}
}
}
double ans = ;
for(int i=;i<=n;i++){
ans = max(ans,f[n][i]);
}
printf("%.12f\n",ans);
return ;
}
[CF442B] Andrey and Problem (概率dp)的更多相关文章
- cf442B Andrey and Problem
B. Andrey and Problem time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- BZOJ 2318: Spoj4060 game with probability Problem( 概率dp )
概率dp... http://blog.csdn.net/Vmurder/article/details/46467899 ( from : [辗转山河弋流歌 by 空灰冰魂] ) 这个讲得很好 , ...
- BZOJ 2318: Spoj4060 game with probability Problem (概率dp)(博弈论)
2318: Spoj4060 game with probability Problem Description Alice和Bob在玩一个游戏.有n个石子在这里,Alice和Bob轮流投掷硬币,如果 ...
- 【bzoj2318】Spoj4060 game with probability Problem 概率dp
题目描述 Alice和Bob在玩一个游戏.有n个石子在这里,Alice和Bob轮流投掷硬币,如果正面朝上,则从n个石子中取出一个石子,否则不做任何事.取到最后一颗石子的人胜利.Alice在投掷硬币时有 ...
- Codeforces 513G1 513G2 Inversions problem [概率dp]
转自九野:http://blog.csdn.net/qq574857122/article/details/43643135 题目链接:点击打开链接 题意: 给定n ,k 下面n个数表示有一个n的排列 ...
- Codeforces Round #253 Div2 D.Andrey and Problem 概率+贪心
概率计算:P(某set) = 令: 和 现在考虑: 1.考虑某个集合,再加一个概率为Pi的朋友后能不能使总概率提高. 即: 由公式可知, 如果 S < 1,则delta > 0,则 ...
- 【BZOJ2318】【spoj4060】game with probability Problem 概率DP
链接: #include <stdio.h> int main() { puts("转载请注明出处[辗转山河弋流歌 by 空灰冰魂]谢谢"); puts("网 ...
- LuoguP2523 [HAOI2011]Problem c(概率DP)
傻逼概率\(DP\),熊大坐这,熊二坐这,两熊体积从右往左挤,挤到\(FFF\)没座位了就不合理了 否则就向左歇斯底里爬,每个\(FFF\)编号就组合一下,完闭 #include <iostre ...
- Andrey and Problem
B. Andrey and Problem time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
随机推荐
- bzoj 3131: [Sdoi2013]淘金
#include<cstdio> #include<iostream> #include<queue> #include<algorithm> #def ...
- HTML5新增Canvas标签及对应属性、API详解(基础一)
知识说明: HTML5新增的canvas标签,通过创建画布,在画布上创建任何想要的形状,下面将canvas的API以及属性做一个整理,并且附上时钟的示例,便于后期复习学习!Fighting! 一.标签 ...
- 用qpython3写一个最简单的发送短信的程序
到目前为止并没有多少手机应用是用python开发的,不过qpython可以作为一个不错的玩具推荐给大家来玩. 写一个最简单的发送短信的程序,代码如下: #-*-coding:utf8;-*- #qpy ...
- Bitcode设置 编译问题
今天在一个iOS培训网站上看到一篇关于第三方库不包含bitcode就会报错的文章,感觉剖析得很详细,分享出来,希望可以对iOS初入门者有所帮助.下面我们就一起来看看吧. 用Xcode 7 beta 3 ...
- php大力力 [042节] 今天做了一个删除功能
php大力力 [042节] 今天做了一个删除功能 if(isset($_GET['action'])){ if($_GET['action']=="del"){ $sql = &q ...
- 浅谈SEO-收录(二)
如何更好的让搜索引擎收录网站中的内容,想要被良好的收录,可以尝试一下几点: 一.机器可读 百度通过一个叫做Baiduspider的程序抓取互联网上的网页, 经过处理后建入索引中,目前只支持读文本,fl ...
- Android RecyclerView单击、长按事件标准实现:基于OnItemTouchListener + GestureDetector
Android RecyclerView单击.长按事件:基于OnItemTouchListener + GestureDetector标准实现 Android RecyclerView虽然拥有L ...
- JavaScript取子串方法slice,substr,substring对比表
在程序语言中,字符串可以说是最常用的一种类型,而在程序中对字符串的操作也是十分频繁.当程序语言自带多种字符串操作的方法时,用该语言编程程序时就有很多的便利性,提高开发的效率.但是当方法过多,甚至目的相 ...
- Adroid 总结--android ListView美化,个性化更改的属性
首先是stackFromBottom属性,这只该属性之后你做好的列表就会显示你列表的最下面,值为true和falseandroid:stackFromBottom="true" ...
- tensorflow2
# step1 加载包import tensorflow as tf import numpy as np # step2 输入:随机产生数据 # Create 100 phony x, y data ...