本文主要是介绍HDU 2955 Robberies(概率DP),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
思路:直接令dp[i][j]表示抢前i个银行,抢了j块钱不被抓的概率是多少,然后就和01背包一样转移就可以了
#include<bits/stdc++.h>
using namespace std;
double dp[10000+5];
double p[105];
int w[105];
int main()
{int T;scanf("%d",&T);while(T--){memset(dp,0,sizeof(dp));int n,sum=0;double maxp;scanf("%lf%d",&maxp,&n);for(int i = 1;i<=n;i++)scanf("%d%lf",&w[i],&p[i]),sum+=w[i];dp[0]=1;for(int i = 1;i<=n;i++)for(int j = sum;j>=w[i];j--)dp[j]=max(dp[j],dp[j-w[i]]*(1-p[i]));int ans = 0;for(int j = 0;j<=sum;j++)if((1-dp[j]) -maxp<1e-6 )ans = max(ans,j);printf("%d\n",ans);}
}
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.
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.
这篇关于HDU 2955 Robberies(概率DP)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!