HDU 2955 变形较大的01背包(有意思,新思路)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955
Robberies
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 29618 Accepted Submission(s): 10834
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
#include<bits/stdc++.h>
using namespace std;
#define max_v 10005
double dp[max_v];//拿k钱的时候的成功逃跑概率
int w[max_v];//每个银行的钱数当作重量
double v[max_v];//每个银行逃跑的概率做价值
//所有银行的总钱数做背包容量
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
double p;
int n;
int sum=;
scanf("%lf %d",&p,&n);
for(int i=;i<n;i++)
{
scanf("%d %lf",&w[i],&v[i]);
sum=sum+w[i];
}
memset(dp,,sizeof(dp));
dp[]=;
for(int i=;i<n;i++)
{
for(int j=sum;j>=w[i];j--)
{
dp[j]=max(dp[j],dp[j-w[i]]*(-v[i]));
}
}
for(int i=sum;i>=;i--)
{
if(dp[i]>(-p))
{
printf("%d\n",i);
break;
}
}
}
return ;
}
HDU 2955 变形较大的01背包(有意思,新思路)的更多相关文章
- HDU 2955 Robberies(0-1背包)
http://acm.hdu.edu.cn/showproblem.php?pid=2955 题意:一个抢劫犯要去抢劫银行,给出了几家银行的资金和被抓概率,要求在被抓概率不大于给出的被抓概率的情况下, ...
- hdu 2955(概率转化,01背包)
Hot~~招聘——巴卡斯(杭州),壹晨仟阳(杭州),英雄互娱(杭州) (包括2016级新生)除了校赛,还有什么途径可以申请加入ACM校队? Robberies Time Limit: 2000/100 ...
- HDU 2955 Robberies (01背包,思路要转换一下,推荐!)
题意: 小A要去抢劫银行,但是抢银行是有风险的,因此给出一个float值P,当被抓的概率<=p,他妈妈才让他去冒险. 给出一个n,接下来n行,分别给出一个Mj和Pj,表示第j个银行所拥有的钱,以 ...
- HDU 2955 Robberies【01背包】
解题思路:给出一个临界概率,在不超过这个概率的条件下,小偷最多能够偷到多少钱.因为对于每一个银行都只有偷与不偷两种选择,所以是01背包问题. 这里有一个小的转化,即为f[v]代表包内的钱数为v的时候, ...
- hdu 2955 Robberies(01背包)
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU 2602 Bone Collector(01背包裸题)
Bone Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDU 2546 饭卡(01背包裸题)
饭卡 Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...
- HDU 2602 - Bone Collector - [01背包模板题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Many years ago , in Teddy’s hometown there was a ...
- HDU 5234 Happy birthday 01背包
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5234 bc:http://bestcoder.hdu.edu.cn/contests/con ...
随机推荐
- js-权威指南学习笔记15.2
1.读取Element的innerHTML属性作为字符串标记返回那个元素的内容. 2.当设置元素的outerHTML时,元素本身被新的内容所替换.只有Element节点定义了outerHTML属性,D ...
- Hibernate初学
什么是Hibernate? Hibernate,翻译过来是冬眠的意思,正好现在已经进入秋季,世间万物开始准备冬眠了.其实对于对象来说就是持久化. 我们从三个角度理解一下Hibernate: 一.Hib ...
- Dynamics 365 App for Outlook 与 Dynamics 365 for Outlook(已被弃用)
在最新的版本中Dynamics 365 for Outlook(Outlook 客户端)已被弃用 随 Dynamics CRM 2016(版本 8.0)引入的 Dynamics 365 App for ...
- ios虚拟机安装 (三)
安装mac系统出现欢迎使用的界面-->一直继续(个人设定) 点击左上角-->Dock-->启动放大 Safari 浏览器
- android中的ellipsize
textview中有个内容过长加省略号的属性,即ellipsize 用法如下: 在xml中 android:ellipsize = "end" 省略号在结尾 android:ell ...
- 润乾V4报表批量打印
背景说明 在应用中,经常遇到,批量打印的需求,批量打印,顾名思义,就是点击一次打印按钮,能打印多张报表. 下面,我们来介绍一下怎么样实现批量打印的 应用举例: Jsp代码 <% //rep ...
- Jquery异步 Deferred Object
Deferred Object )); return dtd.promise();};//使用$.when()为普通操作添加回调函数 为多个操作指定回调函数//$.when(deferred, def ...
- HBase Region分裂实现
分裂策略 不同的分裂策略的实现需要继承RegionSplitPolicy,主要实现两个方法: shouldSplit()表示是否需要分裂 getSplitPoint()得到分裂点rowkey 从 HB ...
- Oracle EBS 获取公司段的本位币
SELECT gls.currency_code FROM hr_organization_information_v t, gl_sets_of_books gls WHERE t.org_info ...
- 一个好玩的计算题目(c++ 位运算)
2015/11/10 在一个qq群里面,看到一个好玩的题目.“int foo(int x){return x&-x} foo(2^31-3)这个怎么算 ?” 1.自己也就开始算了: (1) ...