ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Robberies

2021-04-03 20:01:42  阅读:258  来源: 互联网

标签:probability Robberies pro number int line dp


传送门
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.

Input

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 .
Bank j contains Mj millions, and the probability of getting caught from robbing it is Pj .

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.

思路:

用dp表示获得多少钱可以不被抓的概率,最后从所有银行的总钱数向后开始遍历,若不被抓到的概率大于1-p,则输出i。

#include<bits/stdc++.h>
using namespace std;
#define ll long long
double pro[110];
double dp[10010];
int v[110];

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		memset(dp,0,sizeof(dp));
		memset(pro,0.0,sizeof(pro));
		memset(v,0,sizeof(v));
		double p;
		int n;
		cin>>p>>n;
		dp[0] = 1;
		int sum = 0;
		for(int i = 1; i <= n; i++)
		{
			cin>>v[i]>>pro[i];
			sum += v[i];
		}
		for(int i = 1; i <= n; i++)
		{
			for(int j = sum; j >= v[i]; j--)
			{
				dp[j] = max(dp[j], dp[j - v[i]]*(1.0-pro[i]));
			}
		}
		for(int i = sum; i >= 0; i--)
		{
			if(dp[i] > 1.0 - p)
			{
				printf("%d\n",i);
				break;
			}
		}
	}
}

标签:probability,Robberies,pro,number,int,line,dp
来源: https://blog.csdn.net/p15008340649/article/details/115419723

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有