题意:给出规定的最高被抓概率m,银行数量n,然后给出每个银行被抓概率和钱,问你不超过m最多能拿多少钱

思路:一道好像能直接01背包的题,但是有些不同。按照以往的逻辑,dp[i]都是代表i代价能拿的最高价值,但是这里的代价是小数,显然不能这么做。还有,被抓概率显然不能直接相加,也不能相乘(越乘越小),这里就需要一些转化。我们把被抓概率转化为逃跑概率也就是1-被抓,那么逃跑概率就能直接相乘了。dp[i]代表拿到i价值的最大逃跑概率,这样又变成了01背包。最后求逃跑概率大于等于1-m的最大的钱。

代码:

#include<cstdio>
#include<set>
#include<map>
#include<cmath>
#include<stack>
#include<vector>
#include<queue>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn = +;
const int INF = 0x3f3f3f3f;
double dp[maxn]; //逃跑概率
int val[];
double pr[];
int main(){
int T;
scanf("%d",&T);
while(T--){
double need;
int n,sum = ;
scanf("%lf%d",&need,&n);
need = - need;
for(int i = ;i <= n;i++){
scanf("%d%lf",&val[i],&pr[i]);
sum += val[i];
pr[i] = - pr[i];
}
memset(dp,,sizeof(dp));
dp[] = ;
for(int i = ;i <= n;i++){
for(int j = sum;j >= val[i];j--){
dp[j] = max(dp[j],dp[j - val[i]]*pr[i]);
}
}
int ans = ;
for(int i = sum;i >= ;i--){
if(dp[i] >= need){
ans = i;
break;
}
}
printf("%d\n",ans);
}
return ;
}

HDU 2955 Robberies(概率DP,01背包)题解的更多相关文章

  1. HDU 2955 Robberies抢劫案(01背包,变形)

    题意:要抢劫,但是抢每个银行都有被抓的概率,问在低于规定的被抓概率情况下最多能抢到多少钱. 输入:第一行为T,表示共T个测试例子.每个例子的第一行给出一个浮点数P,是规定被抓的概率上限.第一行还有一个 ...

  2. HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解)

    HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解) 题意分析 要先排序,在做01背包,否则不满足无后效性,为什么呢? 等我理解了再补上. 代码总览 #in ...

  3. HDOJ(HDU).2546 饭卡(DP 01背包)

    HDOJ(HDU).2546 饭卡(DP 01背包) 题意分析 首先要对钱数小于5的时候特别处理,直接输出0.若钱数大于5,所有菜按价格排序,背包容量为钱数-5,对除去价格最贵的所有菜做01背包.因为 ...

  4. HDOJ(HDU).2602 Bone Collector (DP 01背包)

    HDOJ(HDU).2602 Bone Collector (DP 01背包) 题意分析 01背包的裸题 #include <iostream> #include <cstdio&g ...

  5. POJ 2151 Check the difficulty of problems 概率dp+01背包

    题目链接: http://poj.org/problem?id=2151 Check the difficulty of problems Time Limit: 2000MSMemory Limit ...

  6. hdu 1561【树形dp+01背包】

    http://acm.hdu.edu.cn/showproblem.php?pid=1561 很容易想到如果是要攻克v城需要先攻克u城的话,可以建u到v的边.但是如果能够直接攻克u城呢?无边可建,这样 ...

  7. HDU 5234 Happy birthday --- 三维01背包

    HDU 5234 题目大意:给定n,m,k,以及n*m(n行m列)个数,k为背包容量,从(1,1)开始只能往下走或往右走,求到达(m,n)时能获得的最大价值 解题思路:dp[i][j][k]表示在位置 ...

  8. HDU 1864 最大报销额 0-1背包

    HDU 1864 最大报销额 0-1背包 题意 现有一笔经费可以报销一定额度的发票.允许报销的发票类型包括买图书(A类).文具(B类).差旅(C类),要求每张发票的总额不得超过1000元,每张发票上, ...

  9. USACO Money Systems Dp 01背包

    一道经典的Dp..01背包 定义dp[i] 为需要构造的数字为i 的所有方法数 一开始的时候是这么想的 for(i = 1; i <= N; ++i){ for(j = 1; j <= V ...

  10. POJ.3624 Charm Bracelet(DP 01背包)

    POJ.3624 Charm Bracelet(DP 01背包) 题意分析 裸01背包 代码总览 #include <iostream> #include <cstdio> # ...

随机推荐

  1. MQTT-SN协议乱翻之简要介绍

    前言 这一段时间在翻看MQTT-SN的协议,对针对不依赖于TCP传输的MQTT协议十分感兴趣,总是再想着这货到底是怎么定义的.一系列文章皆有MQTT-SN 1.2协议所拼装组成,原文档地址: MQTT ...

  2. diamond types are not supported at this language level

    在intellij导入git项目之后出现 diamond types are not supported at this language level错误 或者String等报错 File->P ...

  3. vim命令删除后重新安装

    个人原创博客,转载请注明,否则追究法律责任 2017-09-30-09:51:20 1,删除vim命令.模拟错误 [root@localhost ~]# which vim/usr/bin/vim[r ...

  4. myBatis调用postgreSQL存储过程

    1.调用没有OUT参数的存储过程: 创建存储过程: create or replace function get_code(a1 varchar(32)) returns varchar(32) as ...

  5. xpath定位方法小结(转载)

    1.实例化一个浏览器WebDriver driver = new FirefoxDriver(); 2.driver.get() get传参数到浏览器中 3.常用定位方法webelement XX=d ...

  6. 04.ActiveMQ与Spring JMS整合

        SpringJMS使用参考:http://docs.spring.io/spring/docs/current/spring-framework-reference/html/jms.html ...

  7. debug kibana in chrome

    kibana5.6.5版本 在kibana根目录运行命令:NODE_OPTIONS='--inspect --debug' npm start 也可以尝试命令:NODE_OPTIONS="- ...

  8. The key unit of modularity in OOP is the class, whereas in AOP the unit of modularity is the aspect.

    Spring Framework Overview https://www.tutorialspoint.com/spring/spring_overview.htm Aspect Oriented ...

  9. talib 中文文档(七):Overlap Studies Functions

    Overlap Studies Functions 重叠指标 BBANDS - Bollinger Bands 函数名:BBANDS 名称: 布林线指标 简介:其利用统计原理,求出股价的标准差及其信赖 ...

  10. php curl采集数据问题汇总

    1. 使用curl获取网页数据提示: "curl: (6) Could not resolve host: xxx.xxx.com ; Name or service not known&q ...