HDU 2955
Robberies
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 20365 Accepted Submission(s): 7535
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.
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
#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的更多相关文章
- HDU 2955 Robberies 背包概率DP
A - Robberies Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- hdu 2955 01背包
http://acm.hdu.edu.cn/showproblem.php?pid=2955 如果认为:1-P是背包的容量,n是物品的个数,sum是所有物品的总价值,条件就是装入背包的物品的体积和不能 ...
- [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了无数发,这道题目给的是被抓的概率,我们应该先求出总的 ...
- poj 3624 && hdu 2955(背包入门)
http://poj.org/problem?id=3624 背包中最基础的01背包,大意是有N件物品和一个容量为V的背包.第i件物品的费用是c[i],价值是w[i].求解将哪些物品装入背包可使价值总 ...
- HDU 2955 Robberies(0-1背包)
http://acm.hdu.edu.cn/showproblem.php?pid=2955 题意:一个抢劫犯要去抢劫银行,给出了几家银行的资金和被抓概率,要求在被抓概率不大于给出的被抓概率的情况下, ...
- HDU 2955 变形较大的01背包(有意思,新思路)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 Robberies Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 2955(01背包)
http://acm.hdu.edu.cn/showproblem.php?pid=2955 这道题求不被抓时的最大金钱.金额是整数,概率是小数.因为数组小标不能是小数,所以我们可以以钱作为weigh ...
- 【01背包变形】Robberies HDU 2955
http://acm.hdu.edu.cn/showproblem.php?pid=2955 [题意] 有一个强盗要去几个银行偷盗,他既想多抢点钱,又想尽量不被抓到.已知各个银行 的金钱数和被抓的概率 ...
随机推荐
- HashMap遍历方式探究
HashMap的遍历有两种常用的方法,那就是使用keyset及entryset来进行遍历,但两者的遍历速度是有差别的,下面请看实例: package com.HashMap.Test; import ...
- 【转】最近搞Hadoop集群迁移踩的坑杂记
http://ju.outofmemory.cn/entry/237491 Overview 最近一段时间都在搞集群迁移.最早公司的hadoop数据集群实在阿里云上的,机器不多,大概4台的样子,据说每 ...
- SU Demos-07NMO
本例还不完善,不足之处,欢迎批评指正 先看readme 第1个脚本,显示速度模型 脚本#2,生成数据 脚本#3,显示合成数据 脚本#4,进行速度分析 脚本#5,动校叠加
- [工作中的设计模式]单例模式singleton
一.模式解析: 单例模式是最简单和最常用的设计模式,面试的时候,不管新毕业的学生还是已经工作多年的筒子,对单例模式基本都能聊上两句.单例模式主要体现在如下方面: 1.类的构造函数私有化,保证外部不能直 ...
- 8659 Mine Sweeping
时间限制:500MS 内存限制:65535K提交次数:37 通过次数:15 题型: 编程题 语言: G++;GCC Description The opening ceremony of the ...
- iOS Debug日志 viewhierarchy调试笔记
Debut - View Debugging - Capture View Hierarchy 当视图没有正常显示时,用view hierarchy进行调试,查看左边的分支里有没有加载对应的视图. 如 ...
- jetty 长时间运行之后出现 PWC6117 file not found
严重: PWC6117: File "%2Ftmp%2Fjetty-0.0.0.0-9090-admin.war-_admin-any-%2Fwebapp%2Ferror%2F404.jsp ...
- Word: How to Temporarily Disable Spell Check in Word
link: http://johnlamansky.com/tech/disable-word-spell-check/ 引用: Word 2010 Click the “File” button C ...
- BZOJ1114 : [POI2008]鲁滨逊逃生Rob
设船最宽行列的交点为船的重心,那么只要预处理出重心在每个位置是否可行,以及在边界上走出边界所需的最小值之后,进行一遍BFS即可. 枚举每个点$(x,y)$,求出它上下最近的障碍物的距离.考虑重心在第$ ...
- BZOJ3591: 最长上升子序列
因为是一个排列,所以可以用$n$位二进制数来表示$O(n\log n)$求LIS时的单调栈. 首先通过$O(n^22^n)$的预处理,求出每种LIS状态后面新加一个数之后的状态. 设$f[i][j]$ ...