DP专题训练之HDU 2955 Robberies
打算专题训练下DP,做一道帖一道吧~~现在的代码风格完全变了~~大概是懒了。所以。将就着看吧~哈哈
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
scenario, the first line of input gives a floating point number P, the
probability Roy needs to be below, and an integer N, the number of banks
he has plans for. Then follow N lines, where line j gives an integer Mj
and a floating point number Pj .
Bank j contains Mj millions, and the probability of getting caught from robbing it is Pj .
Output
he can expect to get while the probability of getting caught is less
than the limit set.
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
Sample Output
题目大意就是:Roy抢劫银行,每家银行都有一定的金额和被抓到的概率,在已知Roy被抓的概率的情况下,求Roy被抓住情况下,可以抢到的最多的钱。
这个题目很坑的点,就是精度不止两位,但是样例却又是。。。。。。唉~
特殊数据就是Roy被抓到的概率接近于0的时候,Roy抢到的钱就是所有银行的金额的和~
简单01背包而已,注意精度问题~~
//Asimple
//#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <limits.h>
#include <time.h>
#define INF 0xfffffff
#define mod 1000000
#define swap(a,b,t) t = a, a = b, b = t
#define CLS(a, v) memset(a, v, sizeof(a))
#define debug(a) cout << #a << " = " << a <<endl
#define abs(x) x<0?-x:x
#define srd(a) scanf("%d", &a)
#define src(a) scanf("%c", &a)
#define srs(a) scanf("%s", a)
#define srdd(a,b) scanf("%d %d",&a, &b)
#define srddd(a,b,c) scanf("%d %d %d",&a, &b, &c)
#define prd(a) printf("%d\n", a)
#define prdd(a,b) printf("%d %d\n",a, b)
#define prs(a) printf("%s\n", a)
#define prc(a) printf("%c", a)
using namespace std;
typedef long long ll;
const int maxn = ;
int n, m, num, T, k, len, ans, sum;
double dp[];
double pp[maxn], p;
int mon[maxn];
void input() {
srd(T);
while( T -- ) {
scanf("%lf %d", &p, &n);
sum = ;
for(int i=; i<n; i++) {
scanf("%d %lf",&mon[i],&pp[i]);
sum += mon[i];
}
CLS(dp, );
dp[] = ;//金额为0时安全
if( p <= -1e- ) {//有被抓的概率
int i;
for(i=; i<n; i++) {
for(int j=sum; j>=mon[i]; j--) {
dp[j] = max(dp[j], (1.0-pp[i])*dp[j-mon[i]]);
}
}
for(i=sum; -dp[i]>=p; i--);
prd(i);
} else {//没有被抓的概率
prd(sum);
}
}
} int main(){
input();
return ;
}
DP专题训练之HDU 2955 Robberies的更多相关文章
- DP专题训练之HDU 1087 Super Jumping!
Description Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!" is ve ...
- DP专题训练之HDU 1231 最大连续子序列
Description 给定K个整数的序列{ N1, N2, ..., NK },其任意连续子序列可表示为{ Ni, Ni+1, ..., Nj },其中 1 <= i <= j < ...
- DP专题训练之HDU 1864 最大报销额
做DP一定要注意数组的大小,嗯,就是这样~ Description 现有一笔经费可以报销一定额度的发票.允许报销的发票类型包括买图书(A类).文具(B类).差旅(C类),要求每张发票的总额不得超过10 ...
- DP专题训练之HDU 1506 Largest Rectangle in a Histogram
Description A histogram is a polygon composed of a sequence of rectangles aligned at a common base l ...
- dp专题训练
****************************************************************************************** 动态规划 专题训练 ...
- HDU 2955 Robberies 背包概率DP
A - Robberies Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- HDU 2955 Robberies(DP)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=2955 题目: Problem Description The aspiring Roy the Rob ...
- 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代价能拿的最高 ...
随机推荐
- php数组合并&去重&恢复索引demo
<?php $tmp = array('a','b','v'); $tmp_1 = array('a','s','asdf'); $res = array_merge($tmp,$tmp_1); ...
- centos7 添加svn
预期目的: 1.仓库放在 /var/svn/ 目录下,并且仓库名为 project 2.创建用户组lsgogroup,该组下添加两个成员lsgoweb1.lsgoweb2,密码直接用用户名,两用户可以 ...
- html5 css3 loading 效果
canvas html5load1 主要思路update 实现12个点的绘制和旋转效果 var update = function() { ctx.save();// 把当前绘图状态保存起来 ct ...
- [原创]快速指定SQLDeveloper所使用JDK的方法
就众多的免费SQL开发工具来讲,Oracle出品的SQLDeveloper 还是一个很不错的选择. 看到网上不少的帖子讨论SQL Developer 启动的时候报告找不到Java Home(或JDK) ...
- scanf、printf、gets、puts的应用及区别
1.scanf()函数 函数scanf()按指定的格式从键盘读取数据,并将其赋给一个或多个变量.例如: scanf(“%d %f”, &x,&rate); 输入多个变量时,scanf ...
- 《奥威Power-BI案例应用:带着漫画看报告》腾讯课程开课啦
元旦小假期过去了,不管是每天只给自己两次下床机会的你,还是唱K看电影逛街样样都嗨的你,是时候重振旗鼓,重新上路了!毕竟为了不给国家的平均工资水平拖后腿,还是要努力工作的.话说2016年已经过去了,什么 ...
- 系统无法开始服务器进程。请检查用户名和密码。 (Exception from HRESULT: 0x8000401A)
开始-运行-cmd,输入aspnet_regiis.exe -i 重新注册iis 或者 出现以下错误:检索 COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-0000 ...
- GPS部标监控平台的架构设计(十一)-基于Memcached的分布式Gps监控平台
部标gps监控平台的架构,随着平台接入的车辆越来越多,架构也面临越来越大的负载挑战,我们当然希望软件尽可能的优化并能够接入更多的车辆,减少在硬件上的投资.但是当车辆增多到某一个临界点的时候,仍然要面临 ...
- 下载VM12 虚拟机和安装kali
为什么现在才写这个-- 因为我在学校啊,学校的电脑还没有kali.好了我们开始. http://www.vmware.com/products/player/playerpro-evaluation ...
- 纪勇破解QQ号问题
试题描述 来到了新学校,才相处不到一个月,jy就对oyjy一见钟情.于是向oyjy问QQ号.当然身为创(实)新(验)一班的同学,oyjy还是要考考jy.她给了纪勇一个加密后的QQ号,让纪勇解密,解密规 ...