Robberies(HDU 2955 DP01背包)
Robberies
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 18013 Accepted Submission(s): 6653
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.
#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背包)的更多相关文章
- Robberies hdu 2955 01背包
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- 【01背包变形】Robberies HDU 2955
http://acm.hdu.edu.cn/showproblem.php?pid=2955 [题意] 有一个强盗要去几个银行偷盗,他既想多抢点钱,又想尽量不被抓到.已知各个银行 的金钱数和被抓的概率 ...
- hdu 2955 01背包
http://acm.hdu.edu.cn/showproblem.php?pid=2955 如果认为:1-P是背包的容量,n是物品的个数,sum是所有物品的总价值,条件就是装入背包的物品的体积和不能 ...
- HDU 2955 01背包(思维)
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- 1 . Robberies (hdu 2955)
The aspiring Roy the Robber has seen a lot of American movies, and knows that the bad guys usually g ...
- 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 1011 树形背包(DP) Starship Troopers
题目链接: HDU 1011 树形背包(DP) Starship Troopers 题意: 地图中有一些房间, 每个房间有一定的bugs和得到brains的可能性值, 一个人带领m支军队从入口(房 ...
- hdu 5445 多重背包
Food Problem Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)To ...
随机推荐
- asp.net mvc4 easyui datagrid 增删改查分页 导出 先上传后导入 NPOI批量导入 导出EXCEL
效果图 数据库代码 create database CardManage use CardManage create table CardManage ( ID ,) primary key, use ...
- 解决位于底端Edittext 输入时被软盘遮盖
遇到这种情况我们首先到网上搜一圈,大概情况是需要设置<activity/> android:windowSoftInputMode="adjustResize" ,按照 ...
- Verilog 模块参数重定义(转)
Verilog重载模块参数: 当一个模块引用另外一个模块时,高层模块可以改变低层模块用parameter定义的参数值,改变低层模块的参数值可采用以下两种方式: 1)defparam 重定义参数语法:d ...
- explorer.exe进程简单介绍
explorer.exe是Windows程序管理器或者Windows资源管理器,它用于管理Windows图形壳,包括开始菜单.任务栏.桌面和文件管理.不过也发现有大量的恶意病毒木马插入到explore ...
- mongodb----pymongo的用法
pymongo是python的一个模块,可能通过sudo pip install pymongo来安装. 导入pymongo import pymongo 创建连接 conn = pymongo.Co ...
- B/S 网站技术选型
Windows平台: http://www.asp.net, http://www.asp.net/mvc Web技术 http://msdn.microsoft.com/ef 数据访问中间件 htt ...
- 算法的稳定性(Stability of Sorting Algorithms)
如果具有同样关键字的纪录的在排序前和排序后相对位置保持不变.一些算法本身就是稳定的,如插入排序,归并排序,冒泡排序等,不稳定的算法有堆排序,快速排序等. 然而,一个本身不稳定的算法通过一点修正也能变成 ...
- <转载>构造函数与拷贝构造函数
原文地址http://www.cnblogs.com/waynelu/archive/2012/07/01/2572264.html 构造函数 构造函数.析构函数与赋值函数是每个类最基本的函数. 对于 ...
- ora-28056 (Writing audit records to Windows Event Log failed)
系统:windows xp oracle 版本 SQL> select * from v$version; BANNER ------------------------------------ ...
- 分割视图控制器(UISplitViewController) 改_masterColumnWidth 导致在 IOS 10中出现闪退
默认UISplitViewController的Master和Detail的宽度是固定的,可以通过下面的方式来改变 [splitViewController setValue:[NSNumber nu ...