Robberies+hdu+01背包问题
来源:互联网 发布:java接口有构造函数吗 编辑:程序博客网 时间:2024/06/10 09:30
Robberies
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 11887 Accepted Submission(s): 4424
Problem Description
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解决方案:此题可以用总的钱数做背包,逃脱概率做价值,则dp[0]=1即没有偷任何东西逃脱概率是1;code:#include<iostream>#include<cstdio>#include<cstring>using namespace std;double dp[10001];struct node{ int coin; double p;} N[101];int main(){ int t; scanf("%d",&t); while(t--) { double p; int sum=0; int n; scanf("%lf %d",&p,&n); p=1-p; for(int i=0; i<n; i++) { scanf("%d %lf",&N[i].coin,&N[i].p); N[i].p=1-N[i].p; sum+=N[i].coin; } memset(dp,0,sizeof(dp)); dp[0]=1; for(int i=0; i<n; i++) { for(int j=sum;j>=N[i].coin;j--){ dp[j]=max(dp[j],dp[j-N[i].coin]*N[i].p); } } int i; for(i=sum;i>=0;i--){ if(dp[i]>=p) break; } printf("%d\n",i); } return 0;}
0 0
- Robberies+hdu+01背包问题
- hdu 2955 Robberies 01背包问题
- [HDU 2955] Robberies (01背包问题)
- HDU 2955 Robberies(01背包问题)
- hdu 2955 Robberies 01背包问题
- hdu 2955(01背包问题)Robberies
- HDU 2955 Robberies(01背包问题)
- Robberies hdu 01 背包
- Robberies 01背包 HDU
- 【HDU 2955】【背包问题】Robberies
- hdu 2955 01 背包 Robberies
- hdu 2955 Robberies--01背包
- Hdu 2955 Robberies//01背包
- hdu 2955 Robberies (01背包)
- hdu 2955 Robberies 01背包
- HDU 2955 Robberies(01背包)
- HDU 2955 Robberies (01背包)
- hdu 2955 Robberies(01背包)
- RabbitMQ三种分布式策略总结
- sublime text 3 常用快捷键收藏
- poj 百练 2808 校门外的树
- 使用SPSS进行Logistic Regression时应注意的问题
- 优秀博文分享
- Robberies+hdu+01背包问题
- 移动web开发经验总结
- 七大内部排序算法总结(插入排序、希尔排序、冒泡排序、简单选择排序、快速排序、归并排序、堆排序)
- poj2828
- C++11新标准学习之花括号初始化列表
- 【Python 2 C++(一)】从python说起
- 学习Zynq-7000的入门书单
- linux 执行 iptables 命令出错 segmentation fault (core dumped) 的解决
- win32_First day