HDU 2955(01背包问题)
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
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
Bank j contains Mj millions, and the probability of getting caught from robbing it is Pj .
Output
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
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
4
6
dp[ j] 表示在抢劫到钱j时不被抓概率。最后,只要找出满足要求的最大j。
代码及案例显示
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int T,n,total;
double p;
double a[],dp[];
int b[];
int main()
{
cin>>T;
while(T--)
{
total=;
cin>>p>>n;
for(int i=; i<n; i++)
{
cin>>b[i]>>a[i];
total+=b[i];
}
memset(dp,,sizeof(dp));
dp[]=; //没抢到钱时,逃脱的概率为1
for(int i=; i<n; i++)
for(int j=total; j>=a[i]; j--)
{
dp[j]=max(dp[j],dp[j-b[i]]*(-a[i]));
//cout<<d[j]<<" "<<j<<endl;
}
for(int i=total; i>=; i--)
{
if(dp[i]>-p)
{
cout<<i<<endl;
break;
}
}
}
return ;
}
下面是第一组案例的各种抢劫钱数的概率

HDU 2955(01背包问题)的更多相关文章
- hdu 2955 01背包
http://acm.hdu.edu.cn/showproblem.php?pid=2955 如果认为:1-P是背包的容量,n是物品的个数,sum是所有物品的总价值,条件就是装入背包的物品的体积和不能 ...
- HDU 1171 (01背包问题)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1171 分析: 例如数据 3 10 2 20 1 30 1 获得这样一个降序的数组: ...
- HDU 2955 01背包(思维)
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- Robberies hdu 2955 01背包
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU 2546 01背包问题
这里5元是个什么意思呢.差不多就是特殊情况了. 就是说最贵的那个东西先不买.并且最后要留下5元去买那个最贵的. 也就是说对现在金钱-5 拿剩下的钱去对减去最贵的商品后的商品dp.看这些剩下的钱能买多少 ...
- HDU _2546 01背包问题
A - 饭卡 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- HDU 1864最大报销额 01背包问题
B - 最大报销额 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit St ...
- HDU 2602 Bone Collector(经典01背包问题)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/O ...
- HDU 3466 Proud Merchants 带有限制的01背包问题
HDU 3466 Proud Merchants 带有限制的01背包问题 题意 最近,伊萨去了一个古老的国家.在这么长的时间里,它是世界上最富有.最强大的王国.因此,即使他们的国家不再那么富有,这个国 ...
- HDU 2602 Bone Collector (01背包问题)
原题代号:HDU 2602 原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 原题描述: Problem Description Many yea ...
随机推荐
- Nodejs in Visual Studio Code 10.IISNode
1.开始 Nodejs in Visual Studio Code 08.IIS : http://www.cnblogs.com/mengkzhaoyun/p/5410185.html 参考此篇内容 ...
- freemarker使用map
freemaker强大的地方是还可以使用map. 一个场景就是对应后端的type类型, type=01,02,03,04, 我们可以在controller定义一个map typeMap,好处就 ...
- 深入了解JavaScript中的for循环
在ECMAScript5中,有三种for循环,分别是: 简单for循环 for-in forEach 在ES6中,新增了一种循环 for-of 简单for循环 const arr = [1, 2, 3 ...
- linux下显卡信息的查看
lspci | grep -i vga 这样就可以显示机器上的显卡信息,比如 [root@localhost conf]# lspci | grep -i vga01:00.0 VGA compat ...
- iOS 10 个实用小技巧(总有你不知道的和你会用到的)
在开发过程中我们总会遇到各种各样的小问题,有些小问题并不是十分容易解决.在此我就总结一下,我在开发中遇到的各种小问题,以及我的解决方法.比较普遍的我就不再提了,这里主要讲一些你可能不知道的(当然,也有 ...
- HDU 4455(dp)
题意:给定一个序列ai,个数为n.再给出一系列w:对于每个w,求序列中,所有长度为w的连续子串中的权值和,子串权值为子串中不同数的个数. 思路:动态规划,用dp[w]表示当前长度为w的时候的权值和.显 ...
- AJAX入门学习(转)
一.基础概念 1.全称:Asynchronous.JavaScript.And.XML(异步的 JavaScript 和 XML). 2.定义: Ajax不是一个技术,它实际上是几种技术,每种技术都有 ...
- webApp禁止用户保存图像
img { -webkit-touch-callout: none; }
- php 在web端读出pdf 与各种文件下载
单纯的下载功能实现 <?php // 表示调用文本类型为pdf的应用 header('Content-type: application/pdf'); // 这句可以输出下载页面进行下载 hea ...
- 初定为EGame
[Q]在纠结到底要用什么方式写博客,是原生态记录框架编写过程(有点所谓的手把手教学的感觉有木有),还是每个模块整合完毕后写分析文章,新手没有写过博客,不知道那种效果好.朋友们给点建议? 这套框架的初衷 ...