Robberies

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 24462    Accepted Submission(s): 9037

Problem Description
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

题目要求的是在不被抓的情况下所能抢的最多的钱。

有小数的是概率,第一个输入的小数是最大的被抓的概率,以后如果抢的被抓的概率大于他的话就会被抓

因为每多抢一家银行就要把被抓的概率相乘,这里用的是不被抓的概率,即如果抢银行不被抓的概率大于我们输入的不被抓的概率那这时就可以成功抢到这笔钱

#include <stdio.h>
#include <math.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <queue>
#define maxn 105
using namespace std;
double n,b[maxn],dp[];
int a[maxn];
int main()
{
int T;
cin >> T;
while(T--){
int m;
cin >> n >> m;
n = - n;
int sum = ;
for(int i=;i<m;i++){
cin >> a[i] >> b[i];
sum += a[i];
b[i] = - b[i];
}
memset(dp,,sizeof(dp));
dp[] = ;
for(int i=;i<m;i++){
for(int j=sum;j>=a[i];j--){
dp[j] = max(dp[j],dp[j-a[i]]*b[i]);//dp出每一个数的不被抓的概率
}
}
for(int j=sum;j>=;j--){
if(dp[j]-n>1e-){//若不被抓的概率大于题目给出的不被抓的概率,则此时所能抢的金额最多(从最大开始的循环)
cout << j << endl;
break;
}
}
}
return ;
}

hdu 2895 01背包 Robberies的更多相关文章

  1. hdu 1203 01背包 I need a offer

    hdu 1203  01背包  I need a offer 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1203 题目大意:给你每个学校得到offe ...

  2. hdu 2955 01背包

    http://acm.hdu.edu.cn/showproblem.php?pid=2955 如果认为:1-P是背包的容量,n是物品的个数,sum是所有物品的总价值,条件就是装入背包的物品的体积和不能 ...

  3. hdu 1864 01背包 最大报销额

    http://acm.hdu.edu.cn/showproblem.php?pid=1864 New~ 欢迎“热爱编程”的高考少年——报考杭州电子科技大学计算机学院关于2015年杭电ACM暑期集训队的 ...

  4. [HDOJ1171]Big Event in HDU(01背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1171 许多有价值的物品,有重复.问如何将他们分成两堆,使两堆价值之差最小. 对价值求和,转换成01背包 ...

  5. HDU 2639 01背包(分解)

    http://acm.hdu.edu.cn/showproblem.php?pid=2639 01背包第k优解,把每次的max分步列出来即可 #include<stdio.h> #incl ...

  6. HDU 1171 01背包

    http://acm.hdu.edu.cn/showproblem.php?pid=1171 基础的01背包,求出总值sum,背包体积即为sum/2 #include<stdio.h> # ...

  7. HDU 2546 01背包

    http://acm.hdu.edu.cn/showproblem.php?pid=2546 经典的01背包 预留5元买最贵的,剩余的就是01背包. #include<stdio.h> # ...

  8. hdoj1171 Big Event in HDU(01背包 || 多重背包)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1171 题意 老师有一个属性:价值(value).在学院里的老师共有n种价值,每一种价值value对应着 ...

  9. HDU 2126 01背包(求方案数)

    Buy the souvenirs Time Limit: 10000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

随机推荐

  1. 搭建谷歌浏览器无头模式抓取页面服务,laravel->php->python->docker !!!

    背景: 公司管理系统需要获取企业微信页面的配置参数如企业名.logo.人数等信息并操作,来隐藏相关敏感信息并自定义简化企业号配置流程 第一版已经实现了扫码登录获取cookie,使用该cookie就能获 ...

  2. 云计算网络基础笔记及VLAN交换机配置

  3. ansible批量管理服务 上

    1 ansible简介 1.1 ansible批量管理服务概述 (1)是基于python语言开发的自动化软件工具(2)是基于SSH远程管理服务实现远程主机批量管理(3)并行管理,部署简单,应用也简单方 ...

  4. IT技术管理者的自我修养

    1. 前言 本来写<IT技术管理者的自我修养>与<IT技术人员的自我修养>是一开始就有的想法.但发表<IT技术人员的自我修养>后,收到了不少良好的反馈,博客园的编辑 ...

  5. Permission 使用详解

    极力推荐文章:欢迎收藏 Android 干货分享 阅读五分钟,每日十点,和您一起终身学习,这里是程序员Android 本篇文章主要介绍 Android 开发中的部分知识点,通过阅读本篇文章,您将收获以 ...

  6. Cookie&Session

    Cookie&Session 背景:Cookie和Session的原理.作用及如何设置和相关面试. 一.诞生背景 HTTP是无状态的,即服务器无法知道两个请求是否来自同一个浏览器,也就是服务器 ...

  7. 百度Echarts,蚂蚁金服G2,D3三种主流可视化工具对比

    1.百度的Echarts 官网:https://echarts.baidu.com/ 介绍:ECharts,缩写来自Enterprise Charts,是百度推出的一款开源的,商业级数据图表,它最初是 ...

  8. node一键发布,并运行

    作为一个前端开发人员如果你只会写一些业务代码,从程序员的角度来考虑已经可以了.但是从架构的角度来考虑那远远不够: 在此记录下成长中的经历: 想要达成的目的:运行一个脚本实现代码的打包,上传至服务器并部 ...

  9. 在一个jsp页面内实现简单计算器

    首先创建一个calculate.jsp 这是用Javascript代码来验证,代码如下: <script type="text/javascript"> functio ...

  10. U盘制作启动盘后空间容量变小解决方法

    WinAll的快速恢复方式: 0.windows键+R(调出运行窗口)输入:diskpart回车(调出磁盘管理器) 1.输入:list disk回车(从大小容量确定目标U盘的盘符X) 2.输入:sel ...