您的位置:首页 > 其它

抢银行 扭向0 1

2016-05-03 12:57 169 查看

Problem V

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 24   Accepted Submission(s) : 8
[align=left]Problem Description[/align]
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.<br><br><center><img src=../../../data/images/con211-1010-1.jpg></center> <br>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.<br><br><br>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.
 

[align=left]Input[/align]
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 . <br>Bank j contains Mj millions, and the probability of getting caught from robbing it is Pj .
 

[align=left]Output[/align]
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.<br><br>Notes and Constraints<br> 0 < T <= 100<br> 0.0 <= P <= 1.0<br> 0
< N <= 100<br> 0 < Mj <= 100<br> 0.0 <= Pj <= 1.0<br> A bank goes bankrupt if it is robbed, and you may assume that all probabilities are independent as the police have very low funds.
 

[align=left]Sample Input[/align]

3
0.04 3
1 0.02
2 0.03
3 0.05
0.06 3
2 0.03
2 0.03
3 0.05
0.10 3
1 0.03
2 0.02
3 0.05

 

[align=left]Sample Output[/align]

2
4
6

 关于抢银行的问题
上来先把失败全部转化为成功的概率
然后逆向dp
对所有的 价钱
分别求出抢到这个价钱最大成功概率
抢到这个价钱的概率
最后 取出 钱数最大概率能成功的 案例
#include<iostream>
#include<string.h>
#include<set>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<math.h>
#include<string.h>
#include<sstream>
#include<stdio.h>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<map>
#include<queue>
#include<iomanip>
#include<cstdio>
using namespace std;
double pao[10000];
int a[10000];
double b[10000];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
memset(pao,0,sizeof(pao));
pao[0]=1;
double t;
int x;
scanf("%lf %d",&t,&x);
t=1-t;
int i,j;
int sum=0;
for(i=1;i<=x;i++)
{
scanf("%d%lf",&a[i],&b[i]);
b[i]=1-b[i];
sum=sum+a[i];
}
for(i=1;i<=x;i++)
{
for(j=sum;j>=a[i];j--)
{
if(pao[j]<pao[j-a[i]]*b[i])
{
pao[j]=pao[j-a[i]]*b[i];
}
}
}
for(i=sum;i>=0;i--)
{
if((pao[i]-t)>0.000000001)
{cout<<i<<endl;
break;
}
}

}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: