HDOJ 2955 Robberies (01背包)
| 10397780 | 2014-03-26 00:13:51 | Accepted | 2955 | 46MS | 480K | 676 B | C++ | 泽泽 |
http://acm.hdu.edu.cn/showproblem.php?pid=2955
Robberies
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 9836 Accepted Submission(s): 3673

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.
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.
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
4
6
#include<stdio.h>
#include<string.h>
int main()
{
int v[];
double f[],w[];
int i,j,n,m;
int T;
scanf("%d",&T);
while(T--)
{
double rate;
int sum=;
scanf("%lf %d",&rate,&n);//rate被抓的概率,1-rate逃脱的概率
for(i=;i<n;i++)
{
scanf("%d %lf",&v[i],&w[i]);
sum+=v[i];
}
memset(f,,sizeof(f));
f[]=;//没偷逃脱的概率为1
for(i=;i<n;i++)
{
for(j=sum;j>=v[i];j--)
{
f[j]=f[j]>f[j-v[i]]*(-w[i])?f[j]:f[j-v[i]]*(-w[i]);//选择最大逃脱概率
}
}
for(i=sum;i>=;i--)
{
if(f[i]>=-rate)
{
printf("%d\n",i);
break;
}
}
}
return ;
}
HDOJ 2955 Robberies (01背包)的更多相关文章
- HDOJ.2955 Robberies (01背包+概率问题)
Robberies 算法学习-–动态规划初探 题意分析 有一个小偷去抢劫银行,给出来银行的个数n,和一个概率p为能够逃跑的临界概率,接下来有n行分别是这个银行所有拥有的钱数mi和抢劫后被抓的概率pi, ...
- 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背包)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 思路:一开始看急了,以为概率是直接相加的,wa了无数发,这道题目给的是被抓的概率,我们应该先求出总的 ...
- 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 (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 ...
- hdoj 2955 Robberies
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
随机推荐
- 编写高质量代码改善C#程序的157个建议[C#闭包的陷阱、委托、事件、事件模型]
前言 本文已更新至http://www.cnblogs.com/aehyok/p/3624579.html .本文主要学习记录以下内容: 建议38.小心闭包中的陷阱 建议39.了解委托的实质 建议40 ...
- Bootstrap3.0学习第十四轮(分页、徽章)
详情请查看http://aehyok.com/Blog/Detail/21.html 个人网站地址:aehyok.com QQ 技术群号:206058845,验证码为:aehyok 本文文章链接:ht ...
- 随堂练习——Rational rose
管理员 学生
- 小菜鸟学Spring-读取属性文件值(三)
Example: the PropertyPlaceholderConfigurer 属性配置文件内容如下所示: jdbc.driverClassName=org.hsqldb.jdbcDriver ...
- 使用TransactionScopeOption 管理事务流
可通过调用一个方法来嵌套事务范围,该方法在使用其自己范围的方法中使用 TransactionScope,下面示例中的 RootMethod 方法就是前者这样的方法. void RootMethod() ...
- 石子合并 区间DP (经典)
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1021 设sum[i][j]为从第i为开始,长度为j的区间的值得和.dp[ ...
- Java设计模式-备忘录模式(Memento)
主要目的是保存一个对象的某个状态,以便在适当的时候恢复对象,个人觉得叫备份模式更形象些,通俗的讲下:假设有原始类A,A中有各种属性,A可以决定需要备份的属性,备忘录类B是用来存储A的一些内部状态,类C ...
- hdu 1166 敌兵布阵--BIT
BIT模版题,学完直接刷毫无压力,水的不要不要的 敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- hihocoder 1181 欧拉路.二
传送门:欧拉路·二 #1181 : 欧拉路·二 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 在上一回中小Hi和小Ho控制着主角收集了分散在各个木桥上的道具,这些道具其 ...
- c++实现gray code(格雷码)
今天别人问的一道题,强调用分治法实现 =.= 百度了一下格雷码,然后写了一下. 关于格雷码大家看百度的吧,特别详细,贴个图: 代码如下(header_file.h是我自己写的一个头文件,包括常见的ve ...