[DP]HDOJ2955 Robberies
来源:互联网 发布:先买java核心技术 编辑:程序博客网 时间:2024/05/16 08:16
[题目]
Robberies
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 16557 Accepted Submission(s): 6084
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
Recommend
gaojie | We have carefully selected several similar problems for you: 1203 2159 2844 1171 1231
[思路]
首先模了一下样例,发现不能判断这个概率是乘还是加,于是看了别人(这个毛病要改)。然后思路就有了,钱的数量作为背包容量,存活概率作为价值,01背包更新已抢i元时最优的概率。
方程:
f[j]=max(f[j],f[j-m[i]]*(1-rp[i]));
f[j-m[i]]*(1-rp[i])>=1-p条件下转移
[代码]
#include <iostream>#include <algorithm>#include <cstring>#include <cstdio>using namespace std;#define LOCALint main(){#ifdef LOCALfreopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);#endifint T,n,m[106],sum,ans;double p,rp[106],dp[10100];cin>>T;while(T--){cin>>p>>n;sum=0;for(int i=0;i<n;++i){cin>>m[i]>>rp[i];sum+=m[i];}for(int i=1;i<=sum;++i) dp[i]=-1.0;dp[0]=1;for(int i=0;i<n;++i)for(int j=sum;j>=m[i];--j)if(dp[j-m[i]]*(1-rp[i])>=1-p)dp[j]=max(dp[j],dp[j-m[i]]*(1-rp[i]));for(int i=sum;i>=0;--i)if(dp[i]>=0){ans=i;break;}cout<<ans<<endl;}return 0;}
0 0
- [DP]HDOJ2955 Robberies
- Robberies(HDOJ2955)
- HDOJ2955 Robberies(01背包,概率)
- hdoj2955
- 【DP(背包)】 hdu2955 Robberies
- hdu 2955 Robberies DP
- hdu Robberies 概率DP
- hdu 2955 Robberies DP
- [HDU2955]Robberies[dp]
- hdu 2955 Robberies dp
- 【基础dp】Robberies
- HDU2955 Robberies DP
- DP专题:HDU_2955-Robberies
- HDU Robberies 2955 dp
- hdu2955 Robberies 01背包 dp
- HDU 2955 Robberies(dp)
- hdu 2955 Robberies(概率,dp)
- HDU_2955 Robberies(DP,01,double)
- AutoCompleteListView,Spinner,Gallery,GridView,ExpandableListView(界面颜值逆天)
- 我是菜鸟:队列同步器
- HDU 4687 Boke and Tsukkomi(一般图匹配|带花树)
- Android照片墙实现 -- 功能介绍
- c++ 创建menu
- [DP]HDOJ2955 Robberies
- 几个数论知识
- 基于块的遍历方式
- Android github上开源项目集合
- LeetCode题解:Minimum Depth of Binary Tree
- C/C++编程题之渊子赛马
- hello word
- python进制转换(读取纯二进制文件内容)
- IP协议头格式分析