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 ...
随机推荐
- mysql的TABLE_SCHEMA的sql和information_schema表, MySQL管理一些基础SQL语句, Changes in MySQL 5.7.2
3.查看库表的最后mysql修改时间, 如果第一次新建的表可能还没有update_time,所以这里用了ifnull,当update_time为null时用create_time替代 select T ...
- 对JVM还一知半解
对JVM还一知半解?这篇文章让你彻底搞定JVM 摘要: 对于Java开发者来说,想把自身能力提升到更高层次,某些JVM相关知识应该是优先级很高的.比如说GC策略,JVM调优. 就我在工作中遇到的情况来 ...
- C# 编程指南
此部分详细介绍了 C# 语言主要功能,以及通过 .NET Framework 可以在 C# 中使用的功能. 阅读此部分的大部分内容的前提是,你已对 C# 和一般编程概念有一定的了解. 如果完全没有接触 ...
- ubuntu下用户的创建、修改
一.1.添加用户 (1)创建一个新的用户username #sudo useradd username (2)设置用户username 的密码 #sudo passwd username 2.添加用户 ...
- IOS学习笔记02---语言发展概述,计算机语言简介.
IOS学习笔记02---语言发展概述,计算机语言简介. ------------------------------------------------------------------------ ...
- Chain of Responsibility 责任链模式 MD
责任链模式 简介 责任链模式是一种对象的行为模式.在责任链模式里,很多对象由每一个对象对其下家的引用而连接起来形成一条链,请求在这个链上[传递],直到链上的某一个对象决定处理此请求.发出这个请求的客户 ...
- MySql的入侵测试以及防范
在做了之前的SQL SERVER之后,便很想尝试一下MYSQL的入侵测试已经防范,与大家一起分享. 总的来说,我一直在用的是MYSQL,对MYSQL比较熟悉,相比较而言,感觉MYSQL更安全,这只是我 ...
- [NPM] Execute Code from a Remote GitHub Branch with npx
We will see how you can use npx to pull and execute code from a GitHub repository. If you need even ...
- [Debug] Debug Node.js Application by using Chrome Dev tools
For example you have a server.js file, and you want to debug some problems; What you can do is: node ...
- leetcode第一刷_ Flatten Binary Tree to Linked List
提示中说明了,改动后的链表相当于原树的前序遍历结果.前序遍历是根左右,因为要把转换后的左子树链接到根节点的右子树上,因此进入递归之后要先把节点的右子树保存下来,然后进入左子树,左子树转换后应该返回最后 ...