Robberies

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

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 <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;
#define eps 0.0000001
int main()
{
int t,b[],i,n,j;
double p,a[],dp[];
scanf("%d",&t);
while(t--)
{
for(i=;i<;i++)dp[i]=;
scanf("%lf%d",&p,&n);
for(i=;i<n;i++)
scanf("%d%lf",&b[i],&a[i]);
dp[]=;
for(i=;i<n;i++)
for(j=-;j>=;j--)
{
if(j-b[i]>=)
dp[j]=min(dp[j-b[i]]*(-a[i])+dp[j-b[i]]*a[i]+(-dp[j-b[i]])*a[i],dp[j]);
} for(i=-;i>;i--)
{
if(dp[i]<=p)break;
//if(i==2)cout<<fabs(dp[i]-p)<<endl;
}
cout<<i<<endl;
}
}
 
 

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

  1. hdu 2955 01背包

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

  2. HDU 2955 01背包(思维)

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

  3. Robberies(HDU 2955 DP01背包)

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

  4. hdu 1203 01背包 I need a offer

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

  5. 【01背包变形】Robberies HDU 2955

    http://acm.hdu.edu.cn/showproblem.php?pid=2955 [题意] 有一个强盗要去几个银行偷盗,他既想多抢点钱,又想尽量不被抓到.已知各个银行 的金钱数和被抓的概率 ...

  6. poj3211Washing Clothes(字符串处理+01背包) hdu1171Big Event in HDU(01背包)

    题目链接: id=3211">poj3211  hdu1171 这个题目比1711难处理的是字符串怎样处理,所以我们要想办法,自然而然就要想到用结构体存储.所以最后将全部的衣服分组,然 ...

  7. Robberies(HDU2955):01背包+概率转换问题(思维转换)

    Robberies  HDU2955 因为题目涉及求浮点数的计算:则不能从正面使用01背包求解... 为了能够使用01背包!从唯一的整数(抢到的钱下手)... 之后就是概率的问题: 题目只是给出被抓的 ...

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

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

  9. Robberies(简单的01背包 HDU2955)

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

随机推荐

  1. jmeter-fileupload操作使用说明

    前言:在http请求过程中上传附件(图片.安装包.视频文件等)虽然基本上Content-Type为:multipart/form-data,但Content-Type也有不一样的,如:图片Conten ...

  2. ps抠图的几种方法

    大家经常会遇到抠图的问题,最多的就是抠人体.头发,抠水,抠树,,,自己经过学习总结了下ps抠图方法,有好几种抠图的方法,我只选择了四种好用的与大家分享 1.色彩范围 比如我们要抠图片上的海水,要抠的图 ...

  3. Tomcat正常启动,访问所有页面均报404异常,404异常总结

    今天遇到一个问题:Tomcat正常启动,访问所有页面均报404异常 404异常,很常见,大多情况是路径错误.web.xml文件映射路径写错.服务器设置.servlet的jar包未导进去或者没有随项目发 ...

  4. 深入理解 JavaScript 中的 replace 方法(转)

    replace方法是属于String对象的,可用于替换字符串. 简单介绍: StringObject.replace(searchValue,replaceValue) StringObject:字符 ...

  5. 第1阶段——u-boot分析之make指令(2)

    通过make 100ask24x0_config 指令配置好芯片选型后,使用make指令来生成uboot.bin文件 本文学习目标: 对Makefile文件进行基本了解,掌握make指令是怎么实现生成 ...

  6. 201521123104 《Java程序设计》第5周学习总结

    1. 本周学习总结 1.1 尝试使用思维导图总结有关多态与接口的知识点 1.2 可选:使用常规方法总结其他上课内容. 1.接口不是类,不能使用new进行实例化; 2.接口可以扩展; 3.接口中可以包含 ...

  7. 201521123049 《JAVA程序设计》 第5周学习总结

    1. 本周学习总结 1.1 尝试使用思维导图总结有关多态与接口的知识点. 2. 书面作业 作业参考文件下载 1.代码阅读:Child压缩包内源代码 1.1 com.parent包中Child.java ...

  8. 201521123050 《Java程序设计》第5周学习总结

    1. 本周学习总结 2. 书面作业 1.代码阅读:Child压缩包内源代码 1.1 com.parent包中Child.java文件能否编译通过?哪句会出现错误?试改正该错误.并分析输出结果. 答:不 ...

  9. 201521123038 《Java程序设计》 第三周学习总结

    201521123038 <Java程序设计> 第三周学习总结 1. 本周学习总结 附大图链接 http://naotu.baidu.com/file/5774caa2be710afbc0 ...

  10. 201521123088《Java程序》第二周总结

    #1. 本章学习总结 ①java基本数据类型 ②String类对象使用 #2. 书面作业 使用Eclipse关联jdk源代码,并查看String对象的源代码(截图)?分析String使用什么来存储字符 ...