hdu 2955(概率转化,01背包)
Robberies
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 18808    Accepted Submission(s): 6941
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.
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 .
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.
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
不被抓的概率就为1-pi,定义dp[i] 代表获得能够获得i亿的情况下不被抓的最大概率,1-dp[i]代表被抓至少一次的最小概率
然后逆序枚举dp 得到第一个 1-dp[k] < p (k从V->0) 即为所求.
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<iostream>
#include <math.h>
#define N 10050 ///背包容量 100*100
using namespace std; int V[];
double p[];
double dp[N]; ///dp[i]表示抢劫i亿元能够不被抓的最大概率
int main()
{
int tcase ;
scanf("%d",&tcase);
while(tcase--){
int n;
double _p;
scanf("%lf%d",&_p,&n);
int sum=;
for(int i=;i<=n;i++){
scanf("%d%lf",&V[i],&p[i]);
sum +=V[i];
p[i]=-p[i];
}
memset(dp,,sizeof(dp));
dp[]=1.0; ///初始化,获得0亿元不被抓的概率为1
for(int i=;i<=n;i++){
for(int v = sum;v>=V[i];v--){
dp[v] = max(dp[v],dp[v-V[i]]*p[i]);
}
}
int max_value=;
for(int k = sum;k>=;k--){
if(-dp[k]<_p) {
max_value = k;
break;
}
}
printf("%d\n",max_value);
}
return ;
}
hdu 2955(概率转化,01背包)的更多相关文章
- HDU 2955 Robberies (01背包,思路要转换一下,推荐!)
		
题意: 小A要去抢劫银行,但是抢银行是有风险的,因此给出一个float值P,当被抓的概率<=p,他妈妈才让他去冒险. 给出一个n,接下来n行,分别给出一个Mj和Pj,表示第j个银行所拥有的钱,以 ...
 - 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 Robberies【01背包】
		
解题思路:给出一个临界概率,在不超过这个概率的条件下,小偷最多能够偷到多少钱.因为对于每一个银行都只有偷与不偷两种选择,所以是01背包问题. 这里有一个小的转化,即为f[v]代表包内的钱数为v的时候, ...
 - hdu 2955 Robberies(01背包)
		
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
 - HDU 5234 Happy birthday 01背包
		
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5234 bc:http://bestcoder.hdu.edu.cn/contests/con ...
 - hdu1203--D - I NEED A OFFER!(转化01背包)
		
D - I NEED A OFFER! Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
 - Hdu 2955 Robberies 0/1背包
		
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
 - HDU 2602 Bone Collector(01背包裸题)
		
Bone Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
 
随机推荐
- Codeforces Round #343 (Div. 2) A
			
A. Far Relative’s Birthday Cake time limit per test 1 second memory limit per test 256 megabytes inp ...
 - noip模拟赛 helloworld
			
分析:对于第一个点,答案为26^n - 25^n,这个很好想.另外30%的点因为n <= 5,所以可以直接暴力搜索. 数学方法不是很好处理,考虑dp,设f[i][j]为前i位匹配到危险串第j位的 ...
 - ACM2647拓扑排序逆运算
			
2647题是对工人排序问题,不是从头到尾排序,而是从尾到头排序: 代码中用到vector和queue容器,权当练习. 用广搜进行拓扑排序的逆运算. #include<iostream> # ...
 - RabbitMQ 作用
			
1.RabbitMQ 作用 同步变异步 解耦 削峰 2.
 - (转)如何在windows 2008 安装IIS
			
首先声明本文转自http://www.pc6.com/infoview/Article_54712.html ,作者为清晨 转载的原因有两个,一是怕原文挂了,而是打算写一下在阿里云部署django的文 ...
 - Object.defineProperty 与 属性描述符
			
为JavaScript对象新增或者修改属性,有两种不同方式:直接使用=赋值或者使用Object.defineProperty 定义,使用后者的话还可以设置属性的描述符. Object.definePr ...
 - String StrigBuffer StringBuilder 浅解
			
1.String是最基本的字符串类,用于表示字符串. 特点:对象内容不可变,但可以通过指向不同的对象来“表示”不同的内容. 使用场景:如果不涉及到内容改变,可以使用String. 注意:如果想将Str ...
 - 任何用户密码都能以sysdba角色登入
			
这是因为在安装Oracle的时候默认是使用了操作系统验证: 数据库用sysdba登录的验证有两种方式,一种是通过os认证,一种是通过密码文件验证:登录方式有两种,一种是在数据库主机直接登录(用os认证 ...
 - 【PHP】Windows下配置用mail()发送邮件
			
ZZ:解决windows系统下php.ini邮件配置正确不发送邮件的问题 php mail()函数在windows不能用,需要安装sendmail,假如是用的XAMPP,则已经下载好,不需要重新下载~ ...
 - vijos 1037 背包+标记
			
描述 2001年9月11日,一场突发的灾难将纽约世界贸易中心大厦夷为平地,Mr. F曾亲眼目睹了这次灾难.为了纪念“9?11”事件,Mr. F决定自己用水晶来搭建一座双塔. Mr. F有N块水晶,每块 ...