Robberies(01背包)
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
题目大意:
给定一个浮点数和整数分别代表最低成功率,以及n户人家,接下来是n行人家的价值以及小偷被抓的概率,求不低于最低成功率能偷到的最大价值。
小偷成功的情况是都要成功,所以概率就是(1-p1)*(1-p2)....
#include <iostream>
#include <cstring>
using namespace std;
double a[],dp[],ans;
int v[];
int n;
int main()
{
int T;
cin>>T;
while(T--)
{
memset(dp,,sizeof dp);
cin>>ans>>n;
int maxn=;
for(int i=;i<=n;i++)
{
cin>>v[i]>>a[i];
maxn+=v[i];///找到最大可能的得到价值
}
dp[]=;
for(int i=;i<=n;i++)
for(int j=maxn;j>=v[i];j--)
dp[j]=max(dp[j],dp[j-v[i]]*(-a[i]));
for(int i=maxn;i>=;i--)
if(dp[i]>=(-ans))
{cout<<i<<'\n';break;}
}
return ;
}
Robberies(01背包)的更多相关文章
- hdu 2955 Robberies 0-1背包/概率初始化
/*Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- HDU 2955 Robberies(01背包变形)
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- hdu 2955 Robberies (01背包好题)
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- hdu 2955 Robberies (01背包)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 思路:一开始看急了,以为概率是直接相加的,wa了无数发,这道题目给的是被抓的概率,我们应该先求出总的 ...
- HDU——2955 Robberies (0-1背包)
题意:有N个银行,每抢一个银行,可以获得\(v_i\)的前,但是会有\(p_i\)的概率被抓.现在要把被抓概率控制在\(P\)之下,求最多能抢到多少钱. 分析:0-1背包的变形,把重量变成了概率,因为 ...
- 【hdu2955】 Robberies 01背包
标签:01背包 hdu2955 http://acm.hdu.edu.cn/showproblem.php?pid=2955 题意:盗贼抢银行,给出n个银行,每个银行有一定的资金和抢劫后被抓的概率,在 ...
- HDU 2955 Robberies --01背包变形
这题有些巧妙,看了别人的题解才知道做的. 因为按常规思路的话,背包容量为浮点数,,不好存储,且不能直接相加,所以换一种思路,将背包容量与价值互换,即令各银行总值为背包容量,逃跑概率(1-P)为价值,即 ...
- HDU 2955 Robberies(01背包)
Robberies Problem Description The aspiring Roy the Robber has seen a lot of American movies, and kno ...
- HDOJ.2955 Robberies (01背包+概率问题)
Robberies 算法学习-–动态规划初探 题意分析 有一个小偷去抢劫银行,给出来银行的个数n,和一个概率p为能够逃跑的临界概率,接下来有n行分别是这个银行所有拥有的钱数mi和抢劫后被抓的概率pi, ...
- HDU2955 Robberies[01背包]
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
随机推荐
- Altium Designer的一些功能
一 Snippets:将原理图或PCB的部分模块电路保存以便于以后重用.https://wenku.baidu.com/view/412a0dbcf121dd36a32d8217.html 二 设备制 ...
- Mysql读写分离操作之mysql-proxy
常见的读写方式 基于程序代码内部实现 在代码中根据select.insert进行选择分类:这类方法也是生产常用的,效率最高,但是对开发人员比较麻烦.架构不能灵活调整 基于中间件的读写分离: mysql ...
- 使用gitblit 在windows平台搭建git服务器
1.下载jdk,安装并且配置好环境变量 2.下载gitblit 直接解压无需安装 3.配置gitblit 1.修改gitblit安装目录下的data文件下的gitblit.properties.将in ...
- AJPFX总结Java 程序初始化过程
觉得Core Java在Java 初始化过程的总体顺序没有讲,只是说了构造器时的顺序,作者似乎认为路径很多,列出来比较混乱.我觉得还是要搞清楚它的过程比较好.所以现在结合我的学习经验写出具体过程: 过 ...
- 关于setTimeout和Promise执行顺序问题
先看一段代码 console.log('打印'+1); setTimeout(function(){ console.log('打印'+2); }) new Promise(function(reso ...
- Android模板制作
本文详细介绍模板相关的知识和如何制作Android模版及使用,便于较少不必要的重复性工作.比如我在工作中如果要创建一个新的模块,就不要需要创建MVP相关的几个类:Model.View.Presente ...
- express搭建平台
1.nodeJs的安装(npm的安装) nodejs官方下载地址:https://nodejs.org 2.express的安装( $ npm install -g express #全局安装expr ...
- Javaweb学习笔记9—过滤器
今天来讲javaweb的第9阶段学习. 过滤器,我在本次的思维导图中将过滤器和监听器放在一起总结了,监听器比较简单就不单独写了. 老规矩,首先先用一张思维导图来展现今天的博客内容. ...
- 深入Docker 存储驱动 (转)
参考: http://static.dockerone.com/ppt/filedriver.html#28
- iptables 防火墙
运行源地址为192.168.10.10-192.168.10.50 这个网段的机器访问本机的20-25还有80.443.6379端口进来的流量 iptables -A INPUT -p tcp -m ...