题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#problem/M
题目:
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<iostream>
#include<cstring>
using namespace std;
double q[],f[];
int m[];
double max(double a,double b)
{
if(a>b) return a;
else return b;
}
int main()
{
int t,n,i,j,M;
double p;
cin>>t;
while(t--)
{
M=;
memset(f,,sizeof(f));
cin>>p>>n;
for(i=;i<=n;i++)
{
cin>>m[i]>>q[i];
M=M+m[i];
}
f[]=;
for(i=;i<=n;i++)
for(j=M;j>=m[i];j--)
f[j]=max(f[j],f[j-m[i]]*(-q[i]));
for(i=M;i>=;i--)
{
if(f[i]>=-p)
{
cout<<i<<endl;
break;
}
}
}
return ;
}