hdu 2955 Robberies(01背包)
Robberies
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 23142 Accepted Submission(s): 8531
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<iostream>
#include<cstdio>
#include<cmath>
#define MAXN 101
#define MAXV 10001 using namespace std; int cost[MAXN];
double weight[MAXV],d[MAXV]; int main()
{
int test,sumv,n,i,j;
double P;
cin>>test;
while(test--)
{
scanf("%lf %d",&P,&n);
P=-P;
sumv=;
for(i=;i<n;i++)
{
scanf("%d %lf",&cost[i],&weight[i]);
weight[i]=-weight[i];
sumv+=cost[i];
}
for(i=;i<=sumv;i++)
d[i]=;
d[]=;
for(i=;i<n;i++)
{
for(j=sumv;j>=cost[i];j--)
{
d[j]=max(d[j],d[j-cost[i]]*weight[i]);
}
}
bool flag=false;
for(i=sumv;i>=;i--)
{
if(d[i]-P>0.000000001)
{
printf("%d\n",i);
break;
}
}
}
return ;
}
hdu 2955 Robberies(01背包)的更多相关文章
- hdu 2955 Robberies (01背包)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 思路:一开始看急了,以为概率是直接相加的,wa了无数发,这道题目给的是被抓的概率,我们应该先求出总的 ...
- 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 (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 (01背包)
10397780 2014-03-26 00:13:51 Accepted 2955 46MS 480K 676 B C++ 泽泽 http://acm.hdu.edu.cn/showproblem. ...
- HDU 2955 【01背包/小数/概率DP】
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- HDOJ.2955 Robberies (01背包+概率问题)
Robberies 算法学习-–动态规划初探 题意分析 有一个小偷去抢劫银行,给出来银行的个数n,和一个概率p为能够逃跑的临界概率,接下来有n行分别是这个银行所有拥有的钱数mi和抢劫后被抓的概率pi, ...
随机推荐
- 小白学习HTTPS
如果你和我一样是HTTPS的小白的话,那就一起来学习这个吧.争取把这篇博客写好,写全面,从原理到实践再到部署. 让我们先来模拟一个场景:当你嗨皮地敲着代码,你的老板偷偷摸摸跑到你的身边,"小 ...
- linux下性能测试工具netperf使用
一.功能简介 netperf是一款针对网络性能的测试工具,主要基于TCP或UDP的传输.根据应用的不同,可以进行批量数据传输(bulk data transfer)模式和请求/应答(request/r ...
- Linux中终端和控制台区别
Linux中终端和控制台区别: 终端:英文名叫terminal 控制台:英文名叫console 两者区别要从以前的多人使用的计算机开始 以前,由于计算机很昂贵,所用一台计算机一般由多个人同时使用.这样 ...
- k8s部署dashborad
环境: 两台虚拟机, 10.10.20.203 部署docker.etcd.flannel.kube-apiserver.kube-controller-manager.kube-scheduler ...
- rsync 删除大量小文件
3 find with delete 复制代码代码如下: test time find ./ -type f -delete find ./ -type f -delete 0.4 ...
- PHP里的socket_recv方法解释
以前一直经为PHP里没有低级的socket帧接收函数,看来是没看仔细,不过那些说明也太少了,(更令人气的里在英文版说明里的例子下有一句话:这个程序不能运行,因为没用listen函数,但在中文版里却没了 ...
- Android Handler警告,SimpleDateFormat警告
1:Handler// This Handler class should be static or leaks might occur: IncomingHandler @SuppressLi ...
- Warning: (3719, “‘utf8’ is currently an alias for the character set UTF8MB3, which will be replaced by UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.”)
[1]本地版本 Mysql 8.0.12 创建表SQL: DROP TABLE IF EXISTS students; CREATE TABLE `students` ( `sId` ) UNSIGN ...
- Android ImageButton的使用。
1.首先是范例代码,一个基本的ImageButton响应. package com.example.arlxsdemo; import android.graphics.Bitmap; import ...
- 成功扩展live555支持ipv6,同时支持RTSPServer & RTSPClient
live555对ipv6的扩展 从live555的官网看live555的发展历史,实在是历史悠久,保守估计已经发展了至少16年以上了,同时,这也导致了live555在很多架构和考虑上面不能满足现代化的 ...