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 ...
随机推荐
- [设计模式] javascript 之 工厂方法模式
1. 简单工厂模式 说明:就是创建一个工厂类,里面实现了所对同一个接口的实现类的创建. 但是好像JavaScript 好像没有 接口 这号东西,所以我们去掉接口这个层; 当然,我们这里的 实现类 下的 ...
- java 获取主机IP
public class Chat extends JFrame { public static JTextField jt; public Chat(){ setLayout(new FlowLay ...
- github的初次体验及管理代码的心得
周六早上的课上,助教给我们演示了一遍如何上传和下载代码库,新建代码库等等,但是是在linux上的,而我的笔记本的操作系统是win7的.而在教室中的尝试因为网络原因,虽然可以上github的网站,但是下 ...
- 小菜鸟学 Spring-bean scope (一)
this information below just for study record of mine. 默认情况下:Spring 创建singleton bean 以便于错误能够被发现. 延迟加载 ...
- Java设计模式-组合模式(Composite)
组合模式有时又叫部分-整体模式在处理类似树形结构的问题时比较方便,看看关系图: 直接来看代码: public class TreeNode { private String name; private ...
- mysql 中如何查找相同的数据
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAbcAAAEYCAIAAABQvy+HAAAAA3NCSVQICAjb4U/gAAAgAElEQVR4Xu
- jquery中的prop和attr比较区别
近期和一同事争执prop和attr的区别,也查了很多,同事说它只是特性和固有属性的区别,但是我也查到了一些其他的,故此,来总结一下吧! 1.固有属性和特别属性 对于HTML元素本身就带有的固有属性,在 ...
- Linux /proc、/dev Principle
目录 . /proc简介 . 内核机制相关 . 进程信息 . 硬件设备相关 . 系统信息 . /dev简介 . 内存相关 1. /proc简介 在linux的根目录下有一个/proc目录,/proc文 ...
- JSP/Servlet基础语法
相关学习资料 http://my.oschina.net/chape/blog/170247 http://docs.oracle.com/cd/E13222_01/wls/docs81/webapp ...
- eclipse启动tomcat错误:A Java Exception has occurred
在tomcat bin目录下执行startup.bat可以正常启动,但在eclipse下安装了tomcat插件并且配置tomcat路径后启动且报错:A Java Exception has occur ...