HDUOJ---2955 Robberies
Robberies
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 9563 Accepted Submission(s): 3575

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.
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.
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
思路: 这道题可以用o/1背包来解答,
思路是将被捕的概率转变为escape的概率,escape=1-catch;
所以抢一个bank,然后都能escape,则抢掉n个bank,逃跑的概率为 tol_escape=escape1*escape2*.....;
这样就可以求出最多能抢到的money啦....
讲的,若果还不明白的话,就再开下代码吧,估计既可以百分百理解了...
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
const int maxn=;
struct bank
{
int m;
float p;
};
bank sta[];
float dp[];
int main()
{
int test;
int toln,i,j,toll;
float tolp;
scanf("%d",&test);
while(test--)
{
scanf("%f%d",&tolp,&toln);
tolp=-tolp;
toll=;
for(i=;i<toln;i++)
{
scanf("%d%f",&sta[i].m,&sta[i].p);
sta[i].p=-sta[i].p; // scape
toll+=sta[i].m; //得到总容量
}
memset(dp,,sizeof(dp));
dp[]=;
for(i=;i<toln;i++)
{
for(j=toll;j>=sta[i].m;j--)
{
if(dp[j]<dp[j-sta[i].m]*sta[i].p)
{
dp[j]=dp[j-sta[i].m]*sta[i].p;
}
}
}
int ans=;
for(j=toll;j>=;j--)
{
if(dp[j]>=tolp)
{
ans=j;
break;
}
}
printf("%d\n",ans);
} return ;
}
HDUOJ---2955 Robberies的更多相关文章
- 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 (01背包+概率问题)
Robberies 算法学习-–动态规划初探 题意分析 有一个小偷去抢劫银行,给出来银行的个数n,和一个概率p为能够逃跑的临界概率,接下来有n行分别是这个银行所有拥有的钱数mi和抢劫后被抓的概率pi, ...
- 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 (动态规划)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 题意是给你一个概率P,和N个银行 现在要去偷钱,在每个银行可以偷到m块钱,但是有p的概率被抓 问 ...
- 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
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 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 Problem Description The aspiring Roy the Robber has seen a lot of American movies, and kno ...
随机推荐
- 《JavaScript启示录》
<JavaScript启示录> 基本信息 作者: (美)Cody Lindley 译者: 徐涛 出版社:人民邮电出版社 ISBN:9787115334947 上架时间:2014-2-21 ...
- spring IOC的常见几种以来注入的方式
在spring ioc中有三种依赖注入,分别是:a.接口注入:b.setter方法注入:c.构造方法注入: 接口注入: public class ClassA { private InterfaceB ...
- tomcat怎么运行servlet程序
新建一个web project 取名 myproject 在myproject 新建一个继承了HttpServlet 的类 MyServlet 重写HttpServlet 的 dopost doget ...
- 混沌数学之Lorenz(洛伦茨)吸引子
洛伦茨吸引子是洛伦茨振子(Lorenz oscillator)的长期行为对应的分形结构,以爱德华·诺顿·洛伦茨的姓氏命名. 洛伦茨振子是能产生混沌流的三维动力系统,是一种吸引子,以其双纽线形状而著称. ...
- 数学图形之SineSurface与粽子曲面
SineSurface直译为正弦曲面.这有可能和你想象的正弦曲线不一样.如果把正弦曲线绕Y轴旋转,得到的该是正弦波曲面.这个曲面与上一节中的罗马曲面有些相似,那个是被捏过的正四面体,这个则是个被捏过正 ...
- C#调用C++ memcpy实现各种参数类型的内存拷贝 VS marshal.copy的实现 效率对比
using System; using System.Runtime.InteropServices; using System.IO; namespace tx { struct ST { publ ...
- Jump Game II leetcode java
题目: Given an array of non-negative integers, you are initially positioned at the first index of the ...
- Linux上如何查看Deb和RPM软件包的更新日志
导读 当一个程序或库打包成Deb或RPM软件包后会有一些元数据文件包含在其中,其中之一就是 changelog文件,它记录了软件包每次更新后发生了什么变化.因此,如果你想找出你安装或更新的软件包发生了 ...
- NGUI诡异的drawCall
看了很多关于NGUI drawCall的文章,见得比较多的一个观点是:一个 Atlas 对应一个Drawcall. 好奇心下做了个demo,两个panel中只用到一个Atlas,却产生了10个draw ...
- Angular路由与Nodejs路由的区别
转自:http://www.imooc.com/qadetail/114683?t=148182 觉得angualr.js的路由是针对于单页面的路由,每次路由发生变化,只是页面的状态发生变化,页面本身 ...