hdu 2955_背包经典
来源:互联网 发布:怎样申请淘宝店 编辑:程序博客网 时间:2024/06/03 20:46
The 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.
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
The 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 .
Bank j contains Mj millions, and the probability of getting caught from robbing it is Pj .
Output
For 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.
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
30.04 31 0.022 0.033 0.050.06 32 0.032 0.033 0.050.10 31 0.032 0.023 0.05
Sample Output
246
一开始以为水题 直接上结果果断wa 因为把dp[i]看做概率为i时能拿到的钱 果断错首先double 难计算到底*10^n? 还有就是不被抓的概率(1-p)*(1-p2)***()所以应该换个思路 用dp[i]看做抢了钱为i时候不被抓的概率 ,最后只要倒着数一下哪个点大于它直接输出就行了
#include#include #include #include #includeusing namespace std;int val[10005];double dp[10005];double weight[10005];void init(){memset(weight,0,sizeof(weight));memset(val,0,sizeof(val));memset(dp,0,sizeof(dp));}int main(){int t;cin>>t;while(t--){double vol;int n;cin>>vol>>n;init();int sum=0;for(int i=1;i<=n;i++){cin>>val[i]>>weight[i];sum+=val[i]; }dp[0]=1;//dp[i]表示的是抢劫的数目为i时不被抓的概率 如果是安全的那么应该 大于1-vol for(int i=1;i<=n;i++){for(int j=sum;j>=val[i];j-=1){dp[j]=max(dp[j],dp[(j-val[i])]*(1-weight[i]));}}for(int i=sum;i>=0;i--) if(dp[i]>(1-vol)){//如果dp的概率是大于安全概率就输出 而且保证了是金额大的 cout<
0 0
- hdu 2955_背包经典
- hdu 2955 Robberies【经典01背包】
- HDU 2602经典背包
- HDU 2955 Robberies(经典01背包概率问题)
- hdu 2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活!_多重背包经典例题!
- hdu 2191多重背包_二进制优化
- HDU 3535 AreYouBusy 经典混合背包
- HDU 3535 AreYouBusy 经典混合背包
- hdu 3535 AreYouBusy(经典分组背包)
- hdu 3535 经典混合分组背包
- hdu 3535 AreYouBusy 经典混合背包
- hdu 3449 Consumer 依赖背包 经典的背包类型
- hdu 2955 小数背包
- HDU-2955 背包问题
- HDU-2955(DP_01背包)
- hdu 2955 01背包
- HDU 2955 背包
- Robberies - HDU 2955 背包
- hdu 5128 The E-pang Palace(几何暴力)
- 解决GAT项目Bug:ETC费用统计问题
- 冒泡算法和交换算法
- ToolBar初步
- 输出eclipse控制台日志到指定目录
- hdu 2955_背包经典
- linux sed查询满足条件在2行记录
- shell脚本中单引号和双引号的区别
- Makefile学习笔记<make指定Makefile或者目标>
- UUID手机端唯一标识
- 南阳OJ 题目75:日期计算
- 设计模式之组合模式
- git fatal: The remote end hung up unexpectedly 错误
- 阿里17春招实习生笔试编程题:实现一个过滤功能,来匹配订阅关系是否符合