Roy the Robber
Problem Description

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
Bank j contains Mj millions, and the probability of getting caught from robbing it is Pj .
Output
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
/*分析:01背包的概率问题
当前的概率基于前一种状态的概率,即偷n家银行而不被抓的概率等于偷n-1家银行不被转的概率乘以偷第n家银行不被抓的概率。
用dp[i]表示偷价值为 i 时不被抓的概率,则状态转移方程为:
dp[j] = max(dp[j] , dp[j-m[i]] * (1-p[i]));
自己写关键在01背包的转换,原意是提供银行个数和期望被捕概率,然后将每个银行的钱数和逃脱概率给出,
通过将总数当作背包大小,通过求最大逃脱概率当作最大价值(但是并不是求这个),最终通过从总钱数递减找到低于期望被捕概率第一项背包,
即为不被逮捕的所能强盗的最大钱数。*/
#include <stdio.h>
#include <string.h> int m[];
double p[],dp[]; int main()
{
int t,n,i,j,sum;
double P;
scanf("%d",&t);
while(t--)
{
scanf("%lf %d",&P,&n);
sum = ;
P = - P;
for(i = ; i < n; i++)
{
scanf("%d %lf",&m[i],&p[i]);
sum += m[i];
p[i] = - p[i];
}
memset(dp,,sizeof(dp));
dp[] = ;
for(i = ; i < n; i++)
for(j = sum; j >= m[i]; j--)
if(dp[j] < dp[j-m[i]]*p[i])
dp[j] = dp[j-m[i]]*p[i];
for(i = sum; i >= &&dp[i] < P; i--);
printf("%d\n",i);
}
return ;
}
Roy the Robber的更多相关文章
- Hdu 2955 Robberies 0/1背包
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- DP专题训练之HDU 2955 Robberies
打算专题训练下DP,做一道帖一道吧~~现在的代码风格完全变了~~大概是懒了.所以.将就着看吧~哈哈 Description The aspiring Roy the Robber has seen a ...
- HDU2955 Robberies[01背包]
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU 2955(0-1背包问题)
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#problem/M 题目: Description The aspir ...
- HDU2955 背包DP
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU 2955
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU 2955 01背包(思维)
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- hdu 2955 01背包
http://acm.hdu.edu.cn/showproblem.php?pid=2955 如果认为:1-P是背包的容量,n是物品的个数,sum是所有物品的总价值,条件就是装入背包的物品的体积和不能 ...
- DP入门---Robberies
HDU 2955 Description The aspiring Roy the Robber has seen a lot of American movies, and knows that ...
随机推荐
- jquery-ui datepicker使用
这是一款老外设计的日期控件 很多显示方式都是国外的 需要自己调整一下 closeText: "Done", prevText: "上一月", nextText: ...
- ASCII码、base64编码 为什么有的代码要用 base64 进行编码?
百度百科 ASCII码:http://baike.baidu.com/link?url=bNtzytBhlSUt_l3pwpfICxCxqgAfqsBMaeWX6QF7gH46Tg4pQtKM2aAV ...
- Swap Nodes in Pairs 解答
Question Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1 ...
- Sum 类型题目总结
Sum类的题目一般这样: input: nums[], target output: satisfied arrays/ lists/ number 拿到题目,首先分析: 1. 是几个数的sum 2. ...
- 【HDU1102】Constructing Roads(MST基础题)
最小生成树水题.prim一次AC #include <iostream> #include <cstring> #include <cstdlib> #includ ...
- 【HDU1325】Is It A Tree?(并查集基础题)
有以下坑点: 1.结束输入不一定-1,题目中的叙述只是说所有权值都为正值. 2.是否构成一棵树不能只判断是否只有一个根节点,没有环路,而且还需要判断每个节点的入度一定是1,不然就不是一棵树. (无环路 ...
- Python开发过程中17个坑
一.不要使用可变对象作为函数默认值 复制代码代码如下: In [1]: def append_to_list(value, def_list=[]): ...: def_list. ...
- pyqt QTreeWidget例子学习
# -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' from PyQt4.QtGui import * from Py ...
- cocos2dx 3.0 研究(4)渲染分析
http://blog.csdn.net/epeaktop/article/details/26730909中已经说明了程序的设计,让我们来看看在cocos2dx 3.0中代码是怎样实现的. void ...
- baidu地图让多个标注出现在最佳视野
原文:http://www.cnblogs.com/milkmap/archive/2011/08/23/2150641.html 摘要: “我有一堆标注,不规则的散落在地图的各个地方,我想把它们展示 ...