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. asp.net mvc4 easyui datagrid 增删改查分页 导出 先上传后导入 NPOI批量导入 导出EXCEL

    效果图 数据库代码 create database CardManage use CardManage create table CardManage ( ID ,) primary key, use ...

  2. 解决位于底端Edittext 输入时被软盘遮盖

    遇到这种情况我们首先到网上搜一圈,大概情况是需要设置<activity/> android:windowSoftInputMode="adjustResize" ,按照 ...

  3. Verilog 模块参数重定义(转)

    Verilog重载模块参数: 当一个模块引用另外一个模块时,高层模块可以改变低层模块用parameter定义的参数值,改变低层模块的参数值可采用以下两种方式: 1)defparam 重定义参数语法:d ...

  4. explorer.exe进程简单介绍

    explorer.exe是Windows程序管理器或者Windows资源管理器,它用于管理Windows图形壳,包括开始菜单.任务栏.桌面和文件管理.不过也发现有大量的恶意病毒木马插入到explore ...

  5. mongodb----pymongo的用法

    pymongo是python的一个模块,可能通过sudo pip install pymongo来安装. 导入pymongo import pymongo 创建连接 conn = pymongo.Co ...

  6. B/S 网站技术选型

    Windows平台: http://www.asp.net, http://www.asp.net/mvc Web技术 http://msdn.microsoft.com/ef 数据访问中间件 htt ...

  7. 算法的稳定性(Stability of Sorting Algorithms)

    如果具有同样关键字的纪录的在排序前和排序后相对位置保持不变.一些算法本身就是稳定的,如插入排序,归并排序,冒泡排序等,不稳定的算法有堆排序,快速排序等. 然而,一个本身不稳定的算法通过一点修正也能变成 ...

  8. <转载>构造函数与拷贝构造函数

    原文地址http://www.cnblogs.com/waynelu/archive/2012/07/01/2572264.html 构造函数 构造函数.析构函数与赋值函数是每个类最基本的函数. 对于 ...

  9. ora-28056 (Writing audit records to Windows Event Log failed)

    系统:windows xp oracle 版本 SQL> select * from v$version; BANNER ------------------------------------ ...

  10. 分割视图控制器(UISplitViewController) 改_masterColumnWidth 导致在 IOS 10中出现闪退

    默认UISplitViewController的Master和Detail的宽度是固定的,可以通过下面的方式来改变 [splitViewController setValue:[NSNumber nu ...