The aspiring Roy the Robber has seen a lot of American movies, and knows that the bad guys usually gets caught in the end, often because they become too greedy. He has decided to work in the lucrative business of bank robbery only for a short while, before retiring to a comfortable job at a university.


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.

 
Input
The first line of input gives T, the number of cases.
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 .
 
Output
For each test case, output a line with the maximum
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.

 
Sample Input
3
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
 
Sample Output
2
4
6
 
给出一个临街概率,求被抓概率不超过此概率的情况下能抢到的最大价值;
由于题目给出的是被抓概率,计算起来没有成功概率方便,我们不妨将失败概率转化为成功概率计算更加容易;
DP[i]:抢到i价值成功的最大概率,不同于背包的一点是,有点“必须装满的感觉”,就是这个i必须要能够被给出的几个价值组合成才可,所以初始化概率为0(dp[0]=1)
{背包:dp[i]:背包大小为i时能获得的最大价值,这道题的话,只要价值无法被组成概率就是0,就是没有固定背包大小,《背包大小成了要求的未知数》!!!
但又多了一重要求:概率要小于给定概率;}
 
综上此题要求的是:在概率满足题目要求的情况下,由给定的几个’物品‘所能组成的最大价值!!!
 
 
代码:

#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)的更多相关文章

  1. Codeforces 28C [概率DP]

    /* 大连热身D题 题意: 有n个人,m个浴室每个浴室有ai个喷头,每个人等概率得选择一个浴室. 每个浴室的人都在喷头前边排队,而且每个浴室内保证大家都尽可能均匀得在喷头后边排队. 求所有浴室中最长队 ...

  2. HDU 4405 Aeroplane chess (概率DP)

    题意:你从0开始,要跳到 n 这个位置,如果当前位置是一个飞行点,那么可以跳过去,要不然就只能掷骰子,问你要掷的次数数学期望,到达或者超过n. 析:概率DP,dp[i] 表示从 i  这个位置到达 n ...

  3. POJ 2096 Collecting Bugs (概率DP)

    题意:给定 n 类bug,和 s 个子系统,每天可以找出一个bug,求找出 n 类型的bug,并且 s 个都至少有一个的期望是多少. 析:应该是一个很简单的概率DP,dp[i][j] 表示已经从 j ...

  4. POJ 2151 Check the difficulty of problems (概率DP)

    题意:ACM比赛中,共M道题,T个队,pij表示第i队解出第j题的概率 ,求每队至少解出一题且冠军队至少解出N道题的概率. 析:概率DP,dp[i][j][k] 表示第 i 个队伍,前 j 个题,解出 ...

  5. 概率DP light oj 1030

    t组数据 n块黄金 到这里就捡起来 出发点1 到n结束  点+位置>n 重掷一次 dp[i] 代表到这里的概率 dp[i]=(dp[i-1]+dp[i-2]... )/6  如果满6个的话 否则 ...

  6. hdu 4050 2011北京赛区网络赛K 概率dp ***

    题目:给出1-n连续的方格,从0开始,每一个格子有4个状态,左右脚交替,向右跳,而且每一步的步长必须在给定的区间之内.当跳出n个格子或者没有格子可以跳的时候就结束了,求出游戏的期望步数 0:表示不能到 ...

  7. [转]概率DP总结 by kuangbin

    概率类题目一直比较弱,准备把kuangbin大师傅总结的这篇题刷一下! 我把下面的代码换成了自己的代码! 原文地址:http://www.cnblogs.com/kuangbin/archive/20 ...

  8. SGU 422 Fast Typing(概率DP)

    题目大意 某人在打字机上打一个字符串,给出了他打每个字符出错的概率 q[i]. 打一个字符需要单位1的时间,删除一个字符也需要单位1的时间.在任意时刻,他可以花 t 的时间检查整个打出来的字符串,并且 ...

  9. HDU 4050 wolf5x(动态规划-概率DP)

    wolf5x Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  10. 概率dp入门

    概率DP主要用于求解期望.概率等题目. 转移方程有时候比较灵活. 一般求概率是正推,求期望是逆推.通过题目可以体会到这点. poj2096:Collecting Bugs #include <i ...

随机推荐

  1. php 写内容到文件,把日志写到log文件

    php 写内容到文件,把日志写到log文件 <?php header("Content-type: text/html; charset=utf-8"); /******** ...

  2. schema与catalog的理解

    sql环境中Catalog和Schema都属于抽象概念,主要用来解决命名冲突问题.一个数据库系统包含多个Catalog,每个Catalog包含多个Schema,每个Schema包含多个数据库对象(表. ...

  3. ACM题目————A Knight's Journey

    Description BackgroundThe knight is getting bored of seeing the same black and white squares again a ...

  4. UVA1714 Keyboarding(bfs)

    UVA1714 Keyboarding bfs 坑点很多的一题(由于一本通的辣鸡翻译会错题意*n). 1.多组数据 2.如果某方向上没有不同字符光标不会动 我们每次预处理出每个点向四个方向下次到达的点 ...

  5. Eclipse启动Tomcat时,45秒超时解决方式

    Eclipse启动Tomcat时,45秒超时解决方式 在Eclipse中启动Tomcat服务器时,经常由于系统初始化项目多,导致出现45秒超时的Tomcat服务器启动错误.  一般通过找到XML配置文 ...

  6. xdebug安装方法

    打开网址:https://xdebug.org/wizard.php 把phpinfo页面中输出的所有内容复制过来,粘贴在此处点下面那个按钮,系统会分析出你需要下载哪个版本的x-debug,还会告诉你 ...

  7. 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 ...

  8. 【Cuda编程】加法归约

    目录 cuda编程并行归约 AtomicAdd调用出错 gpu cpu下时间计算 加法的归约 矩阵乘法 矩阵转置 统计数目 平方和求和 分块处理 线程相邻 多block计算 cuda编程并行归约 At ...

  9. The way to Go(3): 安装Go环境

    Reference: Github: Go Github: The way to Go 在mac上安装Go语言初体验 安装Go环境 Go 语言开发团队开发了适用于以下操作系统的编译器: Linux F ...

  10. C++课程小结 继承与派生

    单继承与多重继承的区别 单继承:一个子类(派生类)只有一个父类(只由一个基类派生而成) 多继承:一个子类(派生类)有多个父类(由多个基类派生而成) 派生类的构成 (1) 从基类继承过来的成员(包括数据 ...