Description
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
Bank j contains Mj millions, and the probability of getting caught from robbing it is Pj .
Output
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
Sample Output
#include<cstdio>
#include<cstring>
#include<algorithm>
int m[1000];//銀行裏的錢
double pp[1000];//搶劫銀行被抓的概率
double dp[10000];
using namespace std;
int main()
{
int T,N;
double P;
scanf("%d",&T);
while(T--)
{
int sum=0;
scanf("%lf%d",&P,&N);
for(int i=0; i<N; i++)
{
scanf("%d%lf",&m[i],&pp[i]);
sum+=m[i];
}
memset(dp,0,sizeof(dp));
dp[0]=1;//搶劫銀行0元錢不被抓的概率爲1
for(int i=0; i<N; i++)
for(int j=sum; j>=m[i]; j--)
dp[j]=max(dp[j],dp[j-m[i]]*(1-pp[i]));
for(int i=sum; i>=0; i--)
{
if(dp[i]>=1-P)
{
printf("%d\n",i);
break;
}
}
}
return 0;
}