Robberies
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 29525 Accepted Submission(s): 10799
Total Submission(s): 29525 Accepted Submission(s): 10799
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
题意:一个人要打劫银行,每个银行有一个打劫失败的概率,同时打劫成功会有一笔收益,只能打劫一次。打劫的人有一个失败的概率上限,求不超过这个上限能抢劫到的最大收益是多少
分析:第一反应是背包,但是背包容量是概率,不好处理,而且最后要得到失败的概率比较麻烦,用成功的概率算。转换一下思路,抢劫的总量是一定的,最多不超过1e4,让抢劫的总量作为容量,dp[j]表示抢劫j价值不被抓的概率的最大值,然后在满足所给概率的条件下,更新一遍最大值即可。
代码
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long LL;
const int maxn = 110;
const int INF = 0x3f3f3f3f;
struct node
{
int v;
double p;
}nod[maxn];
double dp[10010];
int main()
{
int t;
cin>>t;
while(t--)
{
double P;int n;
cin>>P>>n;
for(int i = 1; i <= n; i++)
{
cin>>nod[i].v>>nod[i].p;
nod[i].p = 1.0 - nod[i].p;
}
for(int i = 0; i < 10010; i++)
dp[i] = 0.0;
dp[0] = 1.0;
for(int i = 1; i <= n; i++)
{
for(int j = 10000; j >= nod[i].v; j--)
{
dp[j] = max(dp[j],dp[j - nod[i].v] * nod[i].p);
}
}
int maxx = -1;
for(int i = 0; i <= 10010; i++)
{
if((1.0 - dp[i]) <= P)
maxx = max(maxx,i);
}
cout<<maxx<<endl;
}
return 0;
}
解决一个经典的概率背包问题,通过计算不同银行抢劫方案的成功概率,找到在限定风险下的最大收益。
1万+

被折叠的 条评论
为什么被折叠?



