hdu 2955 Robberies 0-1背包/概率初始化
/*Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 13854 Accepted Submission(s): 5111 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
IDI Open 2009 */
//0-1背包 公式:dp[i] = max(dp[i], dp[i-c]*(1-rp))
#include <cstdio>
#include <cstring>
const int maxn = + ;
double p, pj[maxn], dp[maxn];
int n, mj[maxn], sum;
double Max(double a, double b)
{
return a > b ? a : b;
}
void ZeroOnePack(int m, double rp)
{
for(int i = sum; i >= m; i--){
dp[i] = Max(dp[i], dp[i-m]*(-rp));
}
} int main()
{
int t;
while(~scanf("%d", &t)){
while(t--){
scanf("%lf%d", &p, &n);
sum = ;
for(int i = ; i < n; i++){
scanf("%d%lf", &mj[i], &pj[i]);
sum += mj[i];
}
memset(dp, , sizeof(dp));
dp[] = ;
for(int i = ; i < n; i++)
ZeroOnePack(mj[i], pj[i]);
for(int i = sum; i >= ; i--)
if(dp[i] > -p){
printf("%d\n", i); break;
}
}
}
return ;
}
hdu 2955 Robberies 0-1背包/概率初始化的更多相关文章
- Hdu 2955 Robberies 0/1背包
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU 2955 Robberies(0-1背包)
http://acm.hdu.edu.cn/showproblem.php?pid=2955 题意:一个抢劫犯要去抢劫银行,给出了几家银行的资金和被抓概率,要求在被抓概率不大于给出的被抓概率的情况下, ...
- HDU 2955 Robberies (01背包,思路要转换一下,推荐!)
题意: 小A要去抢劫银行,但是抢银行是有风险的,因此给出一个float值P,当被抓的概率<=p,他妈妈才让他去冒险. 给出一个n,接下来n行,分别给出一个Mj和Pj,表示第j个银行所拥有的钱,以 ...
- hdu 2955 Robberies(01背包)
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU 2955 Robberies【01背包】
解题思路:给出一个临界概率,在不超过这个概率的条件下,小偷最多能够偷到多少钱.因为对于每一个银行都只有偷与不偷两种选择,所以是01背包问题. 这里有一个小的转化,即为f[v]代表包内的钱数为v的时候, ...
- 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 Robberies Time Limit: 2000/1000 MS (Java/Others) ...
- hdu 2955 Robberies(概率背包)
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代价能拿的最高 ...
随机推荐
- Java核心技术卷二部分笔记
第1章 流与文件 1.2 文本输入与输出 第3章 网络 3.3 可中断套接字 第4章 数据库编程 4.5.2 读写LOB 4.6 可滚动和可更新的结果集 4.8 元数据 第6章 高级Swing 6.1 ...
- C#中String和string有什么区别
在C#中,string 是 System.String 的别名,所以基本上在使用时是没有差别的. 习惯上,我们把字符串当作对象时(有值的对象实体),我们用string.而我们把它当类时(需要字符串类中 ...
- Linux数据归档和解压缩tar,cpio,gzip,bzip,lzma,zip命令使用
转载:http://www.1987.name/659.html 数据压缩归档和备份是系统管理的日常工作,定期备份不可小视,归档和压缩对于系统管理员或是普通用户来说都经常用到的操作,有很多中压缩格式, ...
- GCC 编译选项(转)
转:http://www.cnblogs.com/xmphoenix/archive/2011/03/21/1989944.html gcc提供了大量的警告选项,对代码中可能存在的问题提出警 告,通常 ...
- 遍历List remove方法,雨露均沾
/** * 要求:去掉List中为 0 的元素 */ //创建数组和空List Integer[] ars = {1,0,0,0,5,0,8,9,0,0,0,65,3,0,0}; List<In ...
- VC++制作DLL详解
1. DLL的基本概念 应用程序(exe)要引用目标代码(.obj)外部的函数时,有两种实现途径——静态链接和动态链接. 1. 静态链接 链接程序搜索对应的库文件(.lib),然后将这个对 ...
- UIView的生命周期总结
序言: loadView.viewDidLoad.viewDidAppear.initWithNibName.awakeFromNib等经常出现在UIViewController中的方法介绍. 这些方 ...
- 使用 sp_executesql
建议您在执行字符串时,使用 sp_executesql 存储过程而不要使用 EXECUTE 语句.由于此存储过程支持参数替换,因此 sp_executesql 比 EXECUTE 的功能更多:由于 S ...
- centos下添加环境变量和启动apache
#修改环境变量文件 vi /etc/profile #文件内容末尾添上 PATH=/usr/local/php/bin:$PATH export PATH #修改后让环境变量生效 source /et ...
- iOS 10 的一些资料整理
文/判若两人丶(简书作者)原文链接:http://www.jianshu.com/p/0cc7aad638d9 1.iOS 10 隐私权限设置 iOS 10 开始对隐私权限更加严格,如果你不设置就会直 ...