1 . Robberies (hdu 2955)
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.
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
题意 小偷有个总的逃跑概率,每个银行有一个钱数和逃跑概率,问在总的逃跑概率下能最多获得多少钱?
思路:开始有0-1背包写,把概率扩大100倍,wa了,重改思路。把总价格当容量,被抓的概率为价值 在被抓的概率大于总概率时的容量为多少
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <math.h>
#include <vector>
using namespace std;
#define N 10100
#define ll long long
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932
#define met(a,b) memset(a,b,sizeof(a));
vector<vector<int> >Q;
double w[N],dp[N];
int v[N];
int main()
{
int t,sum,n;
double p;
scanf("%d",&t);
while(t--)
{
sum=;
scanf("%lf %d",&p,&n);
p=-p;
for(int i=;i<=n;i++)
{
scanf("%d %lf",&v[i],&w[i]);
w[i]=-w[i];
sum+=v[i];
}
met(dp,);
dp[]=;
for(int i=;i<=n;i++)
{
for(int j=sum;j>=v[i];j--)
dp[j]=max(dp[j],dp[j-v[i]]*w[i]);
}
for(int i=sum;i>=;i--)
{
if(dp[i]>=p)
{
printf("%d\n",i);
break;
}
}
}
return;
}
1 . Robberies (hdu 2955)的更多相关文章
- 【01背包变形】Robberies HDU 2955
http://acm.hdu.edu.cn/showproblem.php?pid=2955 [题意] 有一个强盗要去几个银行偷盗,他既想多抢点钱,又想尽量不被抓到.已知各个银行 的金钱数和被抓的概率 ...
- Robberies(HDU 2955 DP01背包)
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- Robberies hdu 2955 01背包
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- Robberies HDU - 2955
直接说题意吧.(什么网友bb了半天题都说不清楚) 给了 P 表示大于这个概率一定被抓住.则P表示被抓住的概率.N表示现在有的银行,pi表示被抓的概率嘛. 然后,就看数学了.肯定不能算被抓的概率啊. ...
- HDU 2955 Robberies 背包概率DP
A - Robberies Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- [HDU 2955]Robberies (动态规划)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 题意是给你一个概率P,和N个银行 现在要去偷钱,在每个银行可以偷到m块钱,但是有p的概率被抓 问 ...
- HDU 2955 Robberies(DP)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=2955 题目: Problem Description The aspiring Roy the Rob ...
- hdu 2955 Robberies (01背包)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 思路:一开始看急了,以为概率是直接相加的,wa了无数发,这道题目给的是被抓的概率,我们应该先求出总的 ...
- HDU 2955 Robberies(0-1背包)
http://acm.hdu.edu.cn/showproblem.php?pid=2955 题意:一个抢劫犯要去抢劫银行,给出了几家银行的资金和被抓概率,要求在被抓概率不大于给出的被抓概率的情况下, ...
随机推荐
- UVA11038- How Many O's?(组合数学)
题目链接 题意:求出在a到b之间的数中,有多少个0. 思路:组合数学问题.能够枚举每一个位置上的数i,如果i之前的数为left,后面的为right,后面有num位数.当i != 0时,将i置为0,所以 ...
- VirtualBox从USB设备(PE)启动
cmd中执行 VBoxManage internalcommands createrawvmdk -filename E:\usb.vmdk -rawdisk \\.\PhysicalDrive1 - ...
- 基于jQuery的图片相册滑出放大插件
今天给大家带来一款基于jQuery的图片相册滑出放大插件.点击相册图片,展示该图片.该插件适用浏览器:IE8.360.FireFox.Chrome.Safari.Opera.傲游.搜狗.世界之窗..效 ...
- paip.android 手机输入法制造大法
paip.android 手机输入法制造大法 作者Attilax , EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.csdn.net/at ...
- jquery 和 $
而jQuery就是jQuery库提供的一个函数.(好像也不仅仅只是函数, 因为还有 $.ajax(options) 这样的使用,等同 jQuery.ajax(options)) 这个函数的作用是根据 ...
- 开发工具 之 PowerDesigner 应用积累
1.在默认情况下,code与name是联动,修改了name中的数据. 解决方法:设置菜单栏选择"Tools→General Options→Dialog" 中的 "Na ...
- c# checked unchecked 关键字
checked 和 unchecked关键字用来限定检查或者不检查数学运算溢出的:如果使用了checked发生数学运算溢出时会抛出OverflowException:如果使用了unchecked则不会 ...
- js的2种继承方式详解
js中继承可以分为两种:对象冒充和原型链方式 一.对象冒充包括三种:临时属性方式.call()及apply()方式1.临时属性方式 复制代码代码如下: function Person(name){ ...
- SQL操作XML
前面一段时间为了赶项目的进度,一直在加班,现在空闲了下来将前面碰到的问题整理了一下,发现了一些十分有用的,在此记录下来,看能不能帮助到遇到同样问题的朋友,此文仅是自己个人的意见,若存在问题,还望不宁赐 ...
- NSOperation使用系统提供子类的方法--处理复杂任务
//创建一个队列 NSOperationQueue *operation=[[NSOperationQueue alloc]init]; //把任务放在NSBlockOperation里面 NSBlo ...