HDU2955 Robberies DP
来源:互联网 发布:手机在线编程网站 编辑:程序博客网 时间:2024/06/08 07:49
Robberies
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 18802 Accepted Submission(s): 6940
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
Source
IDI Open 2009
题意:一个人要抢银行,每个银行有一个价值V(整数),同时有一个被捕获的概率P,问在低于一定的风险下能获得的最大钱数。
思路:DP。
double dp[10009];//抢了i的钱不被抓的概率
<pre name="code" class="cpp">dp[j]=max(dp[j],dp[j-V[i]]*(1-P[i]));
#include <iostream>#include <stdio.h>#include <math.h>#include <stdlib.h>#include <string>#include <string.h>#include <algorithm>#include <vector>#include <queue>#include <iomanip>#include <time.h>#include <set>#include <map>#include <stack>using namespace std;typedef long long LL;const int INF=0x7fffffff;const int MAX_N=10000;int T,N;double p;double P[120];int V[120];double dp[10009];//抢了i的钱不被抓的概率int main(){ cin>>T; while(T--){ cin>>p>>N; for(int i=0;i<N;i++){ scanf("%d %lf",&V[i],&P[i]); } memset(dp,0,sizeof(dp)); dp[0]=1; for(int i=0;i<N;i++){ for(int j=10000;j>=V[i];j--){ dp[j]=max(dp[j],dp[j-V[i]]*(1-P[i])); } } int ans=0; for(int i=10000;i>=0;i--){ if(dp[i]>1-p){ ans=i; break; } } cout<<ans<<endl; } return 0;}
0 0
- 【DP(背包)】 hdu2955 Robberies
- [HDU2955]Robberies[dp]
- HDU2955 Robberies DP
- hdu2955 Robberies 01背包 dp
- HDU2955 Robberies
- hdu2955-Robberies
- hdu2955 Robberies
- HDU2955 Robberies
- hdu2955 Robberies
- HDU2955-Robberies
- hdu2955 Robberies
- hdu2955 Robberies
- hdu2955 - Robberies
- hdu2955 Robberies
- HDU2955 Robberies
- HDU2955 Robberies
- HDU2955-Robberies
- hdu2955 Robberies
- 小译UnityAPI-Awake,Start,Reset
- ffmpeg 命令行
- 子数组之和为零 lintcode
- 第 0000 题:将你的 QQ 头像(或者微博头像)右上角加上红色的数字,类似于微信未读信息数量那种提示效果。 类似于图中效果
- Javascript 之构造器深入解析
- HDU2955 Robberies DP
- 使用jspSmartUpload组件进行文件上传、下载
- FZU-Problem 2203 单纵大法好(二分+贪心)
- centos7火狐插件安装flash插件;
- 并发和并行的区别
- 关于树莓派的系统安装
- jsp文件上传、下载
- ErrorC2664
- 2016.4.14python排序函数