HDU 2955 Robberies(DP)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=2955
题目:
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
4
6
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n;
double dp[];
double p;
struct node{
int m;
double p;
}bank[];
int main(){
int t;
scanf("%d",&t);
while (t--) {
int total=;
memset(dp, , sizeof(dp));
scanf("%lf%d",&p,&n);
for (int i=; i<n; i++){
scanf("%d%lf",&bank[i].m,&bank[i].p);
total+=bank[i].m;//算出不计概率的情况下,金额总数
}
dp[]=;
for (int i=; i<n; i++) {
for (int j=total; j>=bank[i].m; j--) {
dp[j]=max(dp[j], dp[j-bank[i].m]*(-bank[i].p));
}
}
for (int i=total; i>=; i--) {
if(-dp[i]<p){//dp[i]是逃脱的概率,1-dp[i]是被抓的概率
printf("%d\n",i);
break;
}
}
}
return ;
}
HDU 2955 Robberies(DP)的更多相关文章
- HDU 2955 Robberies 背包概率DP
A - Robberies Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- DP专题训练之HDU 2955 Robberies
打算专题训练下DP,做一道帖一道吧~~现在的代码风格完全变了~~大概是懒了.所以.将就着看吧~哈哈 Description The aspiring Roy the Robber has seen a ...
- hdu 2955 Robberies 背包DP
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU 2955 Robberies(概率DP,01背包)题解
题意:给出规定的最高被抓概率m,银行数量n,然后给出每个银行被抓概率和钱,问你不超过m最多能拿多少钱 思路:一道好像能直接01背包的题,但是有些不同.按照以往的逻辑,dp[i]都是代表i代价能拿的最高 ...
- hdu 2955 Robberies(背包DP)
题意: 小偷去抢银行,他母亲很担心. 他母亲希望他被抓的概率真不超过P.小偷打算去抢N个银行,每个银行有两个值Mi.Pi,Mi:抢第i个银行所获得的财产 Pi:抢第i个银行被抓的概率 求最多能抢得多少 ...
- [HDU 2955]Robberies (动态规划)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 题意是给你一个概率P,和N个银行 现在要去偷钱,在每个银行可以偷到m块钱,但是有p的概率被抓 问 ...
- hdu 2955 Robberies (01背包)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 思路:一开始看急了,以为概率是直接相加的,wa了无数发,这道题目给的是被抓的概率,我们应该先求出总的 ...
- HDU 2955 Robberies(0-1背包)
http://acm.hdu.edu.cn/showproblem.php?pid=2955 题意:一个抢劫犯要去抢劫银行,给出了几家银行的资金和被抓概率,要求在被抓概率不大于给出的被抓概率的情况下, ...
- Hdu 2955 Robberies 0/1背包
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
随机推荐
- pythion 第二弹
################################第二节################################################python中数据类型的常见的方法 ...
- Java数据库连接错误集
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after co ...
- 快学scala
scala 1. scala的由来 scala是一门多范式的编程语言,一种类似java的编程语言[2] ,设计初衷是要集成面向对象编程和函数式编程的各种特性. java和c++的进化速度已经大不如 ...
- 写个百万级别full-stack小型协程库——原理介绍
其实说什么百万千万级别都是虚的,下面给出实现原理和测试结果,原理很简单,我就不上图了: 原理:为了简单明了,只支持单线程,每个协程共享一个4K的空间(你可以用堆,用匿名内存映射或者直接开个数组也都是可 ...
- typecho for SAE
url:http://cloudbbs.org/forum.php?mod=viewthread&tid=22817 typecho和wordpress差不多,目前使用的用户非常之多.这里分享 ...
- MVC架构简介及其测试策略
最近在WEB端测试工作中陷入了瓶颈,单纯的手动功能测试在没有成熟的代码规范之前还是很容易坑的,WEB自动化测试一时半会还没有什么进展,所以决定先学习一下网站用的MVC架构,跟着教程写了一个小网站,大概 ...
- 移动端响应式布局+rem+calc()
1.媒体查询:@media only screen and (max-width: ) {},在最初做pc端时,使用各种媒体查询,因为pc的屏幕分辨率总共就几种,不嫌麻烦的重复使用类名.有很大的缺陷就 ...
- scanner--inputstreamreader--console对比
1 JDK 1.4 及以下版本读取的方法 JDK 1.4 及以下的版本中要想从控制台中输入数据只有一种办法,即使用System.in获得系统的输入流,再桥接至字符流从字符流中读入数据.示例代码如下: ...
- select change事件给其它元素赋值,本select的value或tex
select change事件给其它元素赋值,本select的value或textonchange='$("#areaname").val($("option:selec ...
- undefined variable _session php
解决方法: if (version_compare(PHP_VERSION, '5.4.0', '<')) { if(session_id() == '') {session_start();} ...