Robberies

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 20365    Accepted Submission(s): 7535

Problem Description
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.
 
Input
The first line of input gives T, the number of cases. For each 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
For each test case, output a line with the maximum number of millions 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
3
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
2
4
6
 
Source
 
Recommend
gaojie
题意:
一个人去抢银行,已知在每个银行里能够抢到的钱数和被抓住的概率,又给出了一个被抓住的概率的最大值,问不超过最大被抓概率的前提下最多能够抢多少钱。
思路:
以总钱数为背包容量,求不被抓到的最大概率,最后找出得到最大钱数并且概率合法的情况。正常的二维dp,加了一个滚动数组优化,其实第二维倒着枚举更机智。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = ;
int t, n, a[MAXN];
double dp[][MAXN], P, b[MAXN];
int main()
{
scanf("%d", &t);
while (t--) {
scanf("%lf %d", &P, &n);
P = - P;
int sum = ;
for (int i = ; i <= n; ++i) {
scanf("%d %lf", &a[i], &b[i]);
b[i] = - b[i];
sum += a[i];
}
int ans = , f = ;
memset(dp, , sizeof(dp));
dp[][] = ;
for (int i = ; i <= n; ++i) {
for (int j = ; j <= sum; ++j) {
if (j < a[i]) dp[f][j] = dp[!f][j];
else dp[f][j] = max(dp[!f][j], dp[!f][j - a[i]] * b[i]);
if (dp[f][j] >= P) ans = max(ans, j);
}
f = !f;
}
printf("%d\n", ans);
}
return ;
}

HDU 2955的更多相关文章

  1. HDU 2955 Robberies 背包概率DP

    A - Robberies Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submi ...

  2. hdu 2955 01背包

    http://acm.hdu.edu.cn/showproblem.php?pid=2955 如果认为:1-P是背包的容量,n是物品的个数,sum是所有物品的总价值,条件就是装入背包的物品的体积和不能 ...

  3. [HDU 2955]Robberies (动态规划)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 题意是给你一个概率P,和N个银行 现在要去偷钱,在每个银行可以偷到m块钱,但是有p的概率被抓 问 ...

  4. HDU 2955 Robberies(DP)

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=2955 题目: Problem Description The aspiring Roy the Rob ...

  5. hdu 2955 Robberies (01背包)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 思路:一开始看急了,以为概率是直接相加的,wa了无数发,这道题目给的是被抓的概率,我们应该先求出总的 ...

  6. poj 3624 && hdu 2955(背包入门)

    http://poj.org/problem?id=3624 背包中最基础的01背包,大意是有N件物品和一个容量为V的背包.第i件物品的费用是c[i],价值是w[i].求解将哪些物品装入背包可使价值总 ...

  7. HDU 2955 Robberies(0-1背包)

    http://acm.hdu.edu.cn/showproblem.php?pid=2955 题意:一个抢劫犯要去抢劫银行,给出了几家银行的资金和被抓概率,要求在被抓概率不大于给出的被抓概率的情况下, ...

  8. HDU 2955 变形较大的01背包(有意思,新思路)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 Robberies Time Limit: 2000/1000 MS (Java/Others) ...

  9. HDU 2955(01背包)

    http://acm.hdu.edu.cn/showproblem.php?pid=2955 这道题求不被抓时的最大金钱.金额是整数,概率是小数.因为数组小标不能是小数,所以我们可以以钱作为weigh ...

  10. 【01背包变形】Robberies HDU 2955

    http://acm.hdu.edu.cn/showproblem.php?pid=2955 [题意] 有一个强盗要去几个银行偷盗,他既想多抢点钱,又想尽量不被抓到.已知各个银行 的金钱数和被抓的概率 ...

随机推荐

  1. Codeforces Round #143 (Div. 2) E. Cactus 无向图缩环+LCA

    E. Cactus   A connected undirected graph is called a vertex cactus, if each vertex of this graph bel ...

  2. 几种方式实现Javaweb页面跳转

    背景:       自己经手的一个java项目要实现带参页面跳转和页面跳转,完成任务后,总结一下自己知道了的几种方式. 实现: 首先我们有两大种方式来实现页面跳转:1.JS(javascript):2 ...

  3. NuGet 发布

    其实吧,我并没有用到nuget发布,但是在做项目的过程中,我需要别的系统给我接口,所有吧,人家就发 布了了一个nuget程序集,而我呢,就引用了一下,然后就可以用了,又不吧,本人小编好奇心比较重,所以 ...

  4. SecureCRT中文显示乱码

    环境:SecureCRT登陆REDHAT5.3 LINUX系统 问题:vi编辑器编辑文件时文件中的内容中文显示乱码,但是直接使用linux系统terminal打开此文件时中文显示正常,确诊问题出现在客 ...

  5. LoadRunner下载文件脚本

    LoadRunner下载文件脚本  在看普泽关于pezybase的测试报告的时候,发现里面有用到jmeter(http协议)并发测试下载文件,考虑到后面可能需要在公司pezybase的并发下载,把之前 ...

  6. MVVM模式下实现拖拽

    在文章开始之前先看一看效果图 我们可以拖拽一个"游戏"给ListBox,并且ListBox也能接受拖拽过来的数据, 但是我们不能拖拽一个"游戏类型"给它. 所以 ...

  7. Spring事务解析4-切面织入

    BeanFactoryTransactionAttributeSourceAdvisor作为Advisor的实现类,自然要遵从Advisor的处理方式,当代理被调用时会调用这个类的增强方法,也就是此b ...

  8. AngularJS学习之模块

    1.模块定义了一个应用程序:模块是应用程序中不同部分的容器:模块是应用控制器的容器:控制器通常属于一个模块 2.创建模块:你可以通过AngularJS的angular.module函数来创建模块: & ...

  9. 点击 Run 之后发生了什么?

    这是我以前去链家网面试的一个题目,当时回答不够全面,现在看了2016 WWDC以及Sunnyxx iDev大会的分享之后,感觉对这个问题有了一些简单的认识,就来总结下.如果大家有补充,麻烦评论下哦! ...

  10. LIS(n^2) POJ 2533 Longest Ordered Subsequence

    题目传送门 题意:LIS(Longest Increasing Subsequence)裸题 分析:状态转移方程:dp[i] = max (dp[j]) + 1   (a[j] < a[i],1 ...