HDUOJ---2955 Robberies
Robberies
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 9563 Accepted Submission(s): 3575
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
Source
思路: 这道题可以用o/1背包来解答,
思路是将被捕的概率转变为escape的概率,escape=1-catch;
所以抢一个bank,然后都能escape,则抢掉n个bank,逃跑的概率为 tol_escape=escape1*escape2*.....;
这样就可以求出最多能抢到的money啦....
讲的,若果还不明白的话,就再开下代码吧,估计既可以百分百理解了...
1 #include<stdio.h>
2 #include<string.h>
3 #include<stdlib.h>
4 const int maxn=101;
5 struct bank
6 {
7 int m;
8 float p;
9 };
10 bank sta[101];
11 float dp[10001];
12 int main()
13 {
14 int test;
15 int toln,i,j,toll;
16 float tolp;
17 scanf("%d",&test);
18 while(test--)
19 {
20 scanf("%f%d",&tolp,&toln);
21 tolp=1-tolp;
22 toll=0;
23 for(i=0;i<toln;i++)
24 {
25 scanf("%d%f",&sta[i].m,&sta[i].p);
26 sta[i].p=1-sta[i].p; // scape
27 toll+=sta[i].m; //得到总容量
28 }
29 memset(dp,0,sizeof(dp));
30 dp[0]=1;
31 for(i=0;i<toln;i++)
32 {
33 for(j=toll;j>=sta[i].m;j--)
34 {
35 if(dp[j]<dp[j-sta[i].m]*sta[i].p)
36 {
37 dp[j]=dp[j-sta[i].m]*sta[i].p;
38 }
39 }
40 }
41 int ans=0;
42 for(j=toll;j>=0;j--)
43 {
44 if(dp[j]>=tolp)
45 {
46 ans=j;
47 break;
48 }
49 }
50 printf("%dn",ans);
51 }
52
53
54 return 0;
55 }
- 前端构建:Source Maps详解
- 解决YUM下Loaded plugins: fastestmirror Determining fastest mirrors 的问题
- 被解放的姜戈01 初试天涯
- 被解放的姜戈02 庄园疑云
- eclipse汉化
- Java魔法堂:URI、URL(含URL Protocol Handler)和URN
- 语义化HTML:ul、ol和dl
- 程序员电邮札记
- JavaSE(十)之反射
- windows下安装redis
- Java魔法堂:内部类详解
- jQuery UI Datepicker使用介绍
- CSS魔法堂:Reset CSS
- TCP/IP(六)应用层(DNS和HTTP协议)
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Laravel 5.4前后台分离,通过不同的二级域名访问方法
- Yii框架数据库查询、增加、删除操作示例
- 在laravel5.2中实现点击用户头像更改头像的方法
- laravel 多图上传及图片的存储例子
- Laravel 添加多语言提示信息的方法
- Laravel框架表单验证操作实例分析
- Thinkphp5.0框架视图view的模板布局用法分析
- laravel5环境隐藏index.php后缀(apache)的方法
- php实现对文件压缩简单的方法
- laravel实现Auth认证,登录、注册后的页面回跳方法
- php 实现银联商务H5支付的示例代码
- Yii2.0框架behaviors方法使用实例分析
- laravel 去掉index.php伪静态的操作方法
- laravel 获取某个查询的查询SQL语句方法
- laravel dingo API返回自定义错误信息的实例