Robberies
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10933 Accepted Submission(s): 4049
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.
Bank j contains Mj millions, and the probability of getting caught from robbing it is Pj .
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.
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;
#define eps 0.0000001
int main()
{
int t,b[],i,n,j;
double p,a[],dp[];
scanf("%d",&t);
while(t--)
{
for(i=;i<;i++)dp[i]=;
scanf("%lf%d",&p,&n);
for(i=;i<n;i++)
scanf("%d%lf",&b[i],&a[i]);
dp[]=;
for(i=;i<n;i++)
for(j=-;j>=;j--)
{
if(j-b[i]>=)
dp[j]=min(dp[j-b[i]]*(-a[i])+dp[j-b[i]]*a[i]+(-dp[j-b[i]])*a[i],dp[j]);
} for(i=-;i>;i--)
{
if(dp[i]<=p)break;
//if(i==2)cout<<fabs(dp[i]-p)<<endl;
}
cout<<i<<endl;
}
}