hdu2955(概率DP)

For a few months now,
Roy has been assessing the security of various banks and the amount of cash they
hold. He wants to make a calculated risk, and grab as much money as
possible.
His mother, Ola, has decided upon a tolerable probability
of getting caught. She feels that he is safe enough if the banks he robs
together give a probability less than this.
For each scenario, the first line of input gives a floating point number P, the
probability Roy needs to be below, and an integer N, the number of banks he has
plans for. Then follow N lines, where line j gives an integer Mj and a floating
point number Pj .
Bank j contains Mj millions, and the probability of
getting caught from robbing it is Pj .
number of millions he can expect to get while the probability of getting caught
is less than the limit set.
Notes and Constraints
0 < T <=
100
0.0 <= P <= 1.0
0 < N <= 100
0 < Mj <= 100
0.0
<= Pj <= 1.0
A bank goes bankrupt if it is robbed, and you may assume
that all probabilities are independent as the police have very low funds.
0.04 3
1 0.02
2 0.03
3 0.05
0.06 3
2 0.03
2 0.03
3 0.05
0.10 3
1 0.03
2 0.02
3 0.05
4
6
#include<bits/stdc++.h>
using namespace std;
double dp[10005]; //x下标表示能抢够这个金钱的概率
int main()
{
int T,N,m[105],n,i,j,k,max_money;
double P,p[105];
cin>>T;
while(T--){memset(dp,0,sizeof(dp));
dp[0]=1,max_money=0;
cin>>P>>N;
for(i=1;i<=N;++i) {
cin>>m[i]>>p[i];
p[i]=1.0-p[i];
max_money+=m[i];
}
for(i=1;i<=N;++i)
for(j=max_money;j>=m[i];--j)
dp[j]=max(dp[j],dp[j-m[i]]*p[i]);
for(i=max_money;i>=0;--i) if(dp[i]>1-P||i==0) {cout<<i<<endl;break;}
}
return 0;
}
hdu2955(概率DP)的更多相关文章
- Codeforces 28C [概率DP]
/* 大连热身D题 题意: 有n个人,m个浴室每个浴室有ai个喷头,每个人等概率得选择一个浴室. 每个浴室的人都在喷头前边排队,而且每个浴室内保证大家都尽可能均匀得在喷头后边排队. 求所有浴室中最长队 ...
- HDU 4405 Aeroplane chess (概率DP)
题意:你从0开始,要跳到 n 这个位置,如果当前位置是一个飞行点,那么可以跳过去,要不然就只能掷骰子,问你要掷的次数数学期望,到达或者超过n. 析:概率DP,dp[i] 表示从 i 这个位置到达 n ...
- POJ 2096 Collecting Bugs (概率DP)
题意:给定 n 类bug,和 s 个子系统,每天可以找出一个bug,求找出 n 类型的bug,并且 s 个都至少有一个的期望是多少. 析:应该是一个很简单的概率DP,dp[i][j] 表示已经从 j ...
- POJ 2151 Check the difficulty of problems (概率DP)
题意:ACM比赛中,共M道题,T个队,pij表示第i队解出第j题的概率 ,求每队至少解出一题且冠军队至少解出N道题的概率. 析:概率DP,dp[i][j][k] 表示第 i 个队伍,前 j 个题,解出 ...
- 概率DP light oj 1030
t组数据 n块黄金 到这里就捡起来 出发点1 到n结束 点+位置>n 重掷一次 dp[i] 代表到这里的概率 dp[i]=(dp[i-1]+dp[i-2]... )/6 如果满6个的话 否则 ...
- hdu 4050 2011北京赛区网络赛K 概率dp ***
题目:给出1-n连续的方格,从0开始,每一个格子有4个状态,左右脚交替,向右跳,而且每一步的步长必须在给定的区间之内.当跳出n个格子或者没有格子可以跳的时候就结束了,求出游戏的期望步数 0:表示不能到 ...
- [转]概率DP总结 by kuangbin
概率类题目一直比较弱,准备把kuangbin大师傅总结的这篇题刷一下! 我把下面的代码换成了自己的代码! 原文地址:http://www.cnblogs.com/kuangbin/archive/20 ...
- SGU 422 Fast Typing(概率DP)
题目大意 某人在打字机上打一个字符串,给出了他打每个字符出错的概率 q[i]. 打一个字符需要单位1的时间,删除一个字符也需要单位1的时间.在任意时刻,他可以花 t 的时间检查整个打出来的字符串,并且 ...
- HDU 4050 wolf5x(动态规划-概率DP)
wolf5x Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- 概率dp入门
概率DP主要用于求解期望.概率等题目. 转移方程有时候比较灵活. 一般求概率是正推,求期望是逆推.通过题目可以体会到这点. poj2096:Collecting Bugs #include <i ...
随机推荐
- php 写内容到文件,把日志写到log文件
php 写内容到文件,把日志写到log文件 <?php header("Content-type: text/html; charset=utf-8"); /******** ...
- schema与catalog的理解
sql环境中Catalog和Schema都属于抽象概念,主要用来解决命名冲突问题.一个数据库系统包含多个Catalog,每个Catalog包含多个Schema,每个Schema包含多个数据库对象(表. ...
- ACM题目————A Knight's Journey
Description BackgroundThe knight is getting bored of seeing the same black and white squares again a ...
- UVA1714 Keyboarding(bfs)
UVA1714 Keyboarding bfs 坑点很多的一题(由于一本通的辣鸡翻译会错题意*n). 1.多组数据 2.如果某方向上没有不同字符光标不会动 我们每次预处理出每个点向四个方向下次到达的点 ...
- Eclipse启动Tomcat时,45秒超时解决方式
Eclipse启动Tomcat时,45秒超时解决方式 在Eclipse中启动Tomcat服务器时,经常由于系统初始化项目多,导致出现45秒超时的Tomcat服务器启动错误. 一般通过找到XML配置文 ...
- xdebug安装方法
打开网址:https://xdebug.org/wizard.php 把phpinfo页面中输出的所有内容复制过来,粘贴在此处点下面那个按钮,系统会分析出你需要下载哪个版本的x-debug,还会告诉你 ...
- No compatible targets were found Do you wish to a add new Android Virtual Device ?
运行一个Android小程序时提示: No compatible targets were found Do you wish to a add new Android Virtual Device ...
- 【Cuda编程】加法归约
目录 cuda编程并行归约 AtomicAdd调用出错 gpu cpu下时间计算 加法的归约 矩阵乘法 矩阵转置 统计数目 平方和求和 分块处理 线程相邻 多block计算 cuda编程并行归约 At ...
- The way to Go(3): 安装Go环境
Reference: Github: Go Github: The way to Go 在mac上安装Go语言初体验 安装Go环境 Go 语言开发团队开发了适用于以下操作系统的编译器: Linux F ...
- C++课程小结 继承与派生
单继承与多重继承的区别 单继承:一个子类(派生类)只有一个父类(只由一个基类派生而成) 多继承:一个子类(派生类)有多个父类(由多个基类派生而成) 派生类的构成 (1) 从基类继承过来的成员(包括数据 ...