hdu2955 Robberies (01背包)
转载请注明出处:http://blog.csdn.net/u012860063
题目链接: pid=2955">http://acm.hdu.edu.cn/showproblem.php?pid=2955
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.
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 .
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.
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
2
4
6
pid=1203">1203
2159 2844 1087 1505题意:
抢银行。抢每一个银行被抓的几率为caught[],互为独立事件,在容忍上限内,抢最多的钱。
01背包,但须要改变一点。须要将能抢来的最多的钱最为背包容量
代码例如以下:
/*此题关键是找到背包的容量和价值*/
#include <cstdio>
#include <cstring>
#define N 10047
int M[N];
double P[N],f[N];
double max(double a,double b)
{
if(a > b)
return a;
return b;
}
int main()
{
double p;
int T,n,i,j,sum;
scanf("%d",&T);
while(T--)
{
sum = 0;
memset(f,0,sizeof(f));//要对数组进行初始化
scanf("%lf%d",&p,&n);
p =1-p;;//成功逃走的概率
f[0] = 1;//未抢劫一分钱那么逃走的概率就为1
for(i = 0 ; i < n ; i++)
{
scanf("%d%lf",&M[i],&P[i]);
P[i] = 1-P[i];
sum+=M[i];//算出银行总钱数
}
for(i = 0 ; i < n ; i++)
{
for(j = sum ; j >= M[i] ; j--)
{
f[j] = max(f[j],f[j-M[i]]*P[i]);
}//这里的每次成功的概率须要进行乘法运算。由于是两次成功的概率所以是乘法
}
for(i = sum ; i >= 0 ; i--)
{
if(f[i] >= p)
break;//找出能够成功逃走而且逃走概率不超过警戒值
}
printf("%d\n",i);
}
return 0;
}
hdu2955 Robberies (01背包)的更多相关文章
- HDU2955 Robberies[01背包]
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- Robberies(HDU2955):01背包+概率转换问题(思维转换)
Robberies HDU2955 因为题目涉及求浮点数的计算:则不能从正面使用01背包求解... 为了能够使用01背包!从唯一的整数(抢到的钱下手)... 之后就是概率的问题: 题目只是给出被抓的 ...
- 【hdu2955】 Robberies 01背包
标签:01背包 hdu2955 http://acm.hdu.edu.cn/showproblem.php?pid=2955 题意:盗贼抢银行,给出n个银行,每个银行有一定的资金和抢劫后被抓的概率,在 ...
- 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背包的变形,把重量变成了概率,因为 ...
- 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 ...
随机推荐
- LVS Mode&Method
LVS NAT 模式: Summary: 普通的NAT模式为DNAT,即只更改目的地址,不改源端口. LVS在转发报文时,将Client的源IP透传给Server,类似于透明传输. 优点: 1. 可提 ...
- Codeforces Round #240 (Div. 2) B 好题
B. Mashmokh and Tokens time limit per test 1 second memory limit per test 256 megabytes input standa ...
- input输入框与元素间有间隙
<div class="container"> <button>1</button> <button>2</button> ...
- SQL查询重复记录方法大全 转
原文发布时间为:2010-08-09 -- 来源于本人的百度文章 [由搬家工具导入] 查找所有重复标题的记录: SELECT *FROM t_info aWHERE ((SELECT COUNT(*) ...
- android程序入口
android程序的真正入口是Application类的onCreate方法
- Java使用apache的开源数据处理框架commons-dbutils完成查询结果集的各种处理输出(8种方式)
package demo; /* * QueryRunner数据查询操作: * 调用QueryRunner类方法query(Connection con,String sql,ResultSetHan ...
- hdu 4517(递推枚举统计)
小小明系列故事——游戏的烦恼 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)To ...
- Codeforces Gym100814 B.Unlucky Teacher (ACM International Collegiate Programming Contest, Egyptian Collegiate Programming Contest (2015) Arab Academy for Science and Technology)
今日份的训练题解,今天写出来的题没有昨天多,可能是因为有些事吧... 这个题就是老师改卷子,忘带标准答案了,但是他改了一部分卷子,并且确定自己改的卷子没出错,他想从改过的卷子里把标准答案推出来. 因为 ...
- (8)ftp配置文档
1.vsftpd文件夹中的ftpusers文件的作用 它是一个黑名单,ftpusers不受任何配制项的影响 该文件存放的是一个禁止访问FTP的用户列表 管理员不希望一些拥有过大权限的帐号(比如root ...
- Codeforces Gym 101194C Mr. Panda and Strips(2016 EC-Final,区间DP预处理 + 枚举剪枝)
题目链接 2016 EC-Final 题意 现在要找到数列中连续两个子序列(没有公共部分).要求这两个子序列本身内部没有重复出现的数. 求这两个子序列的长度的和的最大值. 首先预处理一下.令$ ...