hdoj--2955--Robberies(背包好题)
Robberies
Total Submission(s): 17709 Accepted Submission(s): 6539
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.
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 .
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.
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
2
4
6
刚开始一直用概率作条件判断,但是一直错,后来听别人建议,就改成了钱作条件,背包里存入概率,但是同时发生的事情概率应该相乘
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define MAX(a,b)(a>b?a:b)
int main()
{
int T, i, j, n, money[110];
float P, p[110], dp[10010];
int k=1;
scanf("%d",&T);
while(T--)
{
memset(dp,0,sizeof(dp));
int sum = 0;
scanf("%f%d",&P,&n);
P=1-P;
for(i=1;i<=n; i++)
{
scanf("%d%f",&money[i],&p[i]);
sum += money[i];
p[i] =(1-p[i]);
}
dp[0] = 1;
for(int i=1;i<=n;i++)
{
for(int j=sum;j>=money[i];j--)
{
dp[j]=MAX(dp[j],dp[j-money[i]]*p[i]);
}
}
int i;
for(i=sum;i>=0;i--)
{
if(dp[i]>=P)
break;
}
printf("Case %d: %d\n",k++,i);
}
return 0;
}
hdoj--2955--Robberies(背包好题)的更多相关文章
- HDOJ.2955 Robberies (01背包+概率问题)
Robberies 算法学习-–动态规划初探 题意分析 有一个小偷去抢劫银行,给出来银行的个数n,和一个概率p为能够逃跑的临界概率,接下来有n行分别是这个银行所有拥有的钱数mi和抢劫后被抓的概率pi, ...
- HDOJ 2955 Robberies (01背包)
10397780 2014-03-26 00:13:51 Accepted 2955 46MS 480K 676 B C++ 泽泽 http://acm.hdu.edu.cn/showproblem. ...
- HDU 2955 Robberies 背包概率DP
A - Robberies Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- hdoj 2955 Robberies
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- hdu 2955 Robberies 背包DP
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- hdu 2955 Robberies (01背包好题)
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代价能拿的最高 ...
- HDU 1712 ACboy needs your help (分组背包模版题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712 有n门课,和m天时间.每门课上不同的天数有不同的价值,但是上过这门课后不能再上了,求m天里的最大 ...
- hdu 2191 珍惜现在,感恩生活 多重背包入门题
背包九讲下载CSDN 背包九讲内容 多重背包: hdu 2191 珍惜现在,感恩生活 多重背包入门题 使用将多重背包转化为完全背包与01背包求解: 对于w*num>= V这时就是完全背包,完全背 ...
- HDU 1248 寒冰王座(全然背包:入门题)
HDU 1248 寒冰王座(全然背包:入门题) http://acm.hdu.edu.cn/showproblem.php?pid=1248 题意: 不死族的巫妖王发工资拉,死亡骑士拿到一张N元的钞票 ...
随机推荐
- svn 验证位置失败 Authorization failed
进入svn的conf目录下 修改svnserve.conf [general] anon-access = none #未登录用户不允许访问 auth-access = write passwor ...
- Linux Shell脚本编程-信号捕获
bash编程的信号捕获: kill -l 显示当前系统可用信号(trap -l) 获取帮助:man 7 single 常用信号: 1) SIGHUP 无须重启进程而让其重读配置文件 2) SI ...
- [HAOI2009]毛毛虫(树形dp)
[HAOI2009]毛毛虫 题目描述 对于一棵树,我们可以将某条链和与该链相连的边抽出来,看上去就象成一个毛毛虫,点数越多,毛毛虫就越大.例如下图左边的树(图 1 )抽出一部分就变成了右边的一个毛毛虫 ...
- 在pycharm中配置Anaconda以及pip源配置
在学习推荐系统.机器学习.数据挖掘时,python是非常强大的工具,也有很多很强大的模块,但是模块的安装却是一件令人头疼的事情. 现在有个工具--anaconda,他已经帮我们集成好了很多工具了!an ...
- ubuntu鼠标和触摸板的禁用
ubuntu鼠标和触摸板的禁用 学习了:http://www.2cto.com/os/201308/239403.html 在终端下直接执行以下命令来打开或关闭触摸板. sudo modprobe - ...
- glm编译错误问题解决 formal parameter with __declspec(align('16')) won't be aligned
參考:http://stackoverflow.com/questions/25300116/directxxmmatrix-error-c2719-declspecalign16-wont-be-a ...
- 19.允许重复的unordered_map
#include <string> #include <iostream> //查询性能最高 //允许重复的,hash_map #include <unordered_m ...
- Everedit软件下载、安装和运行(免注册)
不多说,最近,无意中,留意到这款软件. 前言 1.这是免注册版本 (推荐,这个是别人开发做出来的,放心!) 2.这是需注册版本 (这个是去官网) EverEdit是专门为国人设计的一流文本 ...
- PGA和UGA内存的使用情况
引用thomas kyte的PGA和UGA的统计内存的使用情况,用排序区不同的大小来查看pga.UGA.物理读取不同内存使用 会话1:创建测试表和测试不同排序大小 create table t as ...
- Windows 10问题
微软修复Windows updat 工具WindowsUpdateDiagnostic.diagcab: http://download.microsoft.com/download/F/2/2/F2 ...