1 . Robberies (hdu 2955)
The aspiring Roy the Robber has seen a lot of American movies, and knows that the bad guys usually gets caught in the end, often because they become too greedy. He has decided to work in the lucrative business of bank robbery only for a short while, before retiring to a comfortable job at a university.

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
题意 小偷有个总的逃跑概率,每个银行有一个钱数和逃跑概率,问在总的逃跑概率下能最多获得多少钱?
思路:开始有0-1背包写,把概率扩大100倍,wa了,重改思路。把总价格当容量,被抓的概率为价值 在被抓的概率大于总概率时的容量为多少
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <math.h>
#include <vector>
using namespace std;
#define N 10100
#define ll long long
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932
#define met(a,b) memset(a,b,sizeof(a));
vector<vector<int> >Q;
double w[N],dp[N];
int v[N];
int main()
{
int t,sum,n;
double p;
scanf("%d",&t);
while(t--)
{
sum=;
scanf("%lf %d",&p,&n);
p=-p;
for(int i=;i<=n;i++)
{
scanf("%d %lf",&v[i],&w[i]);
w[i]=-w[i];
sum+=v[i];
}
met(dp,);
dp[]=;
for(int i=;i<=n;i++)
{
for(int j=sum;j>=v[i];j--)
dp[j]=max(dp[j],dp[j-v[i]]*w[i]);
}
for(int i=sum;i>=;i--)
{
if(dp[i]>=p)
{
printf("%d\n",i);
break;
}
}
}
return;
}
1 . Robberies (hdu 2955)的更多相关文章
- 【01背包变形】Robberies HDU 2955
http://acm.hdu.edu.cn/showproblem.php?pid=2955 [题意] 有一个强盗要去几个银行偷盗,他既想多抢点钱,又想尽量不被抓到.已知各个银行 的金钱数和被抓的概率 ...
- Robberies(HDU 2955 DP01背包)
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 ...
- 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 2955]Robberies (动态规划)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 题意是给你一个概率P,和N个银行 现在要去偷钱,在每个银行可以偷到m块钱,但是有p的概率被抓 问 ...
- HDU 2955 Robberies(DP)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=2955 题目: Problem Description The aspiring Roy the Rob ...
- 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 题意:一个抢劫犯要去抢劫银行,给出了几家银行的资金和被抓概率,要求在被抓概率不大于给出的被抓概率的情况下, ...
随机推荐
- knockout 监控数组的缺点
knockout的监控数组没有想象中的强大,只能监控数组元素的位置变化,或个数的增减,然后对视图对应区域进行同步. <!DOCTYPE html> <html> <hea ...
- 信号之signal函数
UNIX系统的信号机制最简单的接口是signal函数.signal函数的功能:为指定的信号安装一个新的信号处理函数. #include <signal.h> void (*signal(i ...
- 基于CSS3图片可倾斜摆放的动画相册
今天我们又要来分享一个CSS3动画相册.之前我们分享过一个很酷的放满女神的HTML5/CSS3相册,相册是全屏展示的.今天这款相册的特点是图片可以任意角度的倾斜摆放,就像随意放在桌面上一样.另外,当鼠 ...
- Transact-SQL三值逻辑
/*===========================<一>========================== 在SQL中逻辑表达式的值有三种: 1.TRUE 2.FALSE 3.U ...
- LeetCode17 Letter Combinations of a Phone Number
题意: Given a digit string, return all possible letter combinations that the number could represent. A ...
- Android 高级UI设计笔记20:RecyclerView 的详解之RecyclerView添加Item点击事件
1. 引言: RecyclerView侧重的是布局的灵活性,虽说可以替代ListView但是连基本的点击事件都没有,这篇文章就来详细讲解如何为RecyclerView的item添加点击事件,顺便复习一 ...
- Android(java)学习笔记267:Android线程池形态
1. 线程池简介 多线程技术主要解决处理器单元内多个线程执行的问题,它可以显著减少处理器单元的闲置时间,增加处理器单元的吞吐能力. 假设一个服务器完成一项任务所需时间为:T1 创建线程时间, ...
- iOS篇之有沙盒缓存
内存指的就是主板上的存储部件,是CPU直接与之沟通,并用其存储数据的部件,存放当前正在使用的(即执行中)的数据和程序,它的物理实质就是一组或多组具备数据输入输出和数据存储功能的集成电路,内存只用于暂时 ...
- 【原创】mac 上如何安装及切换输入法
1. 安装输入法 刚购入mac mini一台,默认只有英文输入法,而自己用习惯了sogou输入法,于是就在网上下载安装了一个sogou拼音输入 for mac. 下载完毕后,在屏幕下方的dock区域右 ...
- apache2.4 +django1.9+python3+ubuntu15.10
这是我这几天学习部署django的总结,中间出现了不少的问题.特此记录下来,用来复习巩固,同时也希望给想学习的同学一些参考. 第一步:我在ubuntu上装的是python3.sudo apt-get ...