Robberies

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 18013    Accepted Submission(s): 6653

Problem Description
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.

 
Input
The first line of input gives T, the number of cases. For each scenario, the first line of input gives a floating point number P, the probability Roy needs to be below, and an integer N, the number of banks he has plans for. Then 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 .
 
Output
For each test case, output a line with the maximum number of millions he can expect to get while the probability of getting caught is less than the limit set.

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.

 
Sample Input
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
 
 
Sample Output
2
4
6
用逃脱概率比作价值,所抢钱数比作背包容量。
 #include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
float dp[+];
struct node
{
int a;
float b;
}f[];
int main()
{
int T,i,j,n;
float p;
freopen("in.txt","r",stdin);
scanf("%d",&T);
while(T--)
{
int sum=;
memset(dp,,sizeof(dp));
scanf("%f%d",&p,&n);
for(i=;i<=n;i++)
{
scanf("%d%f",&f[i].a,&f[i].b);
f[i].b=-f[i].b;
sum+=f[i].a;
}
dp[]=1.0;
for(i=;i<=n;i++)
{
for(j=sum;j>=f[i].a;j--)
{
if(dp[j]<dp[j-f[i].a]*f[i].b)
dp[j]=dp[j-f[i].a]*f[i].b;
}
}
for(i=sum;i>=;i--)
if(dp[i]>=(1.0-p))
break;
printf("%d\n",i);
}
return ;
}

Robberies(HDU 2955 DP01背包)的更多相关文章

  1. Robberies hdu 2955 01背包

    Robberies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  2. 【01背包变形】Robberies HDU 2955

    http://acm.hdu.edu.cn/showproblem.php?pid=2955 [题意] 有一个强盗要去几个银行偷盗,他既想多抢点钱,又想尽量不被抓到.已知各个银行 的金钱数和被抓的概率 ...

  3. hdu 2955 01背包

    http://acm.hdu.edu.cn/showproblem.php?pid=2955 如果认为:1-P是背包的容量,n是物品的个数,sum是所有物品的总价值,条件就是装入背包的物品的体积和不能 ...

  4. HDU 2955 01背包(思维)

    Robberies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  5. 1 . Robberies (hdu 2955)

    The aspiring Roy the Robber has seen a lot of American movies, and knows that the bad guys usually g ...

  6. Robberies HDU - 2955

    直接说题意吧.(什么网友bb了半天题都说不清楚) 给了  P  表示大于这个概率一定被抓住.则P表示被抓住的概率.N表示现在有的银行,pi表示被抓的概率嘛. 然后,就看数学了.肯定不能算被抓的概率啊. ...

  7. HDU 2955 Robberies 背包概率DP

    A - Robberies Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submi ...

  8. HDU 1011 树形背包(DP) Starship Troopers

    题目链接:  HDU 1011 树形背包(DP) Starship Troopers 题意:  地图中有一些房间, 每个房间有一定的bugs和得到brains的可能性值, 一个人带领m支军队从入口(房 ...

  9. hdu 5445 多重背包

    Food Problem Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)To ...

随机推荐

  1. 了不起的分支和循环01 - 零基础入门学习Python007

    了不起的分支和循环01 让编程改变世界 Change the world by program 我们今天的主题是"了不起的分支和循环",为什么小甲鱼不说C语言,不说Python了不 ...

  2. CloudStack API编程指引

    原文地址:https://cwiki.apache.org/confluence/display/CLOUDSTACK/CloudStack+API+Coding+Guidelines 前言 本文阐述 ...

  3. 【破解】破解ACDSEE15的方法

    1.先从官方下载一个ACDSEE15简体中文版 2.下载注册机(点我下载) 3.修改注册表 修改注册表ACDSee 32位:HKEY_LOCAL_MACHINE\SOFTWARE\ACD System ...

  4. PHP中$_GET['name']与$_POST['name']变量直接用变量名$name的php配置

    php中,可以直接使用参数名称作为变量来接收get或post的传参,条件是php.ini中register_global设置成On 另外一种方法: if(!ini_get('register_glob ...

  5. Oracle查看表空间及修改数据文件大小

    Oracle查看表空间及修改数据文件大小 第一步:查看所有表空间及表空间大小: select tablespace_name ,sum(bytes) / 1024 / 1024 as MB from ...

  6. iotop

    iotop命令是专门显示硬盘IO的命令,界面风格类似top命令.这个命令只有在kernelv2.6.20及以后的版本中才有.   1.直接yum安装,rh6的光盘里有包. yum install io ...

  7. 逻辑数据库设计 - 需要ID(谈主键Id)

    本文的目标就是要确认那些使用了主键,却混淆了主键的本质而造成的一种反模式. 一.确立主键规范 每个了解数据库设计的人都知道,主键对于一张表来说是一个很重要,甚至必需的部分.这确实是事实,主键是好的数据 ...

  8. 《Programming WPF》翻译 第5章 8.我们进行到哪里了?

    原文:<Programming WPF>翻译 第5章 8.我们进行到哪里了? 样式支持你定义一个策略来设置可视化元素的依赖属性.属性的设置可以被命名以及手动或者编程方式地通过名称应用,或者 ...

  9. 关于sencha touch 的JSONP跨域请求的学习研究

    此篇文章是对自己在研究学习sencha touch的过程中的点滴记录,主要是JSONP的跨域请求这方面,对于何为是跨域概念还有不熟悉的,可以自己问下度娘. 先上张图: 我要完成的功能就是表格下拉刷新, ...

  10. ofbiz安装优化

    一. 1.安装jdk 2.安装数据库 3.安装ant yum install ant 4.编译启动ofbiz cd /ofbiz目录下 ant run-install ./startofbiz.sh ...