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. 【好程序员笔记分享】——Cocoapods集成

    -iOS培训,iOS学习-------型技术博客.期待与您交流!------------ Xcode集成POD教程 准备工作: 首先我们要在我们的电脑中安装POD,进入命令行,输入如下指令 sudo  ...

  2. 用RBG颜色设置自定义颜色

    这个是Mac自带的测色计   快捷键shift + command + c即可复制RBG格式的颜色 #DD0000 这个是csdn 的logo里的红色 我们得到的是十六位颜色代码 但是UIColor( ...

  3. wordpress博客搬家心得

    更改SSH的连接端口和登录账户 在SSH的配置文件,/etc/ssh/sshd_config中找到Port 22(一般情况下是22, 根据服务器提供商的设置而不同)更改为你自己希望的端口. 至于登录账 ...

  4. Js,alert出现乱码问题,赶紧记下来,额~~~

    原文 http://www.cnblogs.com/still-windows7/archive/2011/08/28/2156010.html 前些天还可以正常使用的js文件,在添加了一些东西后,其 ...

  5. C3P0连接池详细配置

    C3P0连接池详细配置 转自http://msq.javaeye.com/blog/60387 <c3p0-config> <default-config> <!--当连 ...

  6. Java实现配置加载机制

    前言 现如今几乎大多数Java应用,例如我们耳熟能详的tomcat, struts2, netty…等等数都数不过来的软件,要满足通用性,都会提供配置文件供使用者定制功能. 甚至有一些例如Netty这 ...

  7. 理解mcelog如何工作

    前言 本文,带你了解几个问题? 本文重点,主要看案例2,带你很好的理解mcelog如何工作的? mcelog的干什么的? mcelog 是 x86 的 Linux 系统上用来 检查硬件错误,特别是内存 ...

  8. input里面check 状态检测

    if($("#check_status").attr('checked')) //检测checkbox状态 { //checked状态 }else { //不是checked状态 ...

  9. Win7 公布网站 HTTP 错误 404.4 - Not Found

     NET IIS7.5 创建网站时,假设发现下面错误,而且 默认网站訪问没有问题的话, 能够尝试,进入 处理程序映射 右键恢复为父级,有可能会有意想不到的 惊喜. 我的问题就是这样解决的. 出现这 ...

  10. 自定义TypeConverter把基础类型转换为复杂类型

    原文(http://tech.it168.com/d/2008-06-30/200806300953554_all.shtml) TypeConverter对于编写ASP.NET Server Con ...