集训第六周 数学概念与方法 概率 N题
Description
As Harry Potter series is over, Harry has no job. Since he wants to make quick money, (he wants everything quick!) so he decided to rob banks. He wants to make a calculated risk, and grab as much money as possible. But his friends - Hermione and Ron have decided upon a tolerable probabilityP of getting caught. They feel that he is safe enough if the banks he robs together give a probability less than P.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case contains a real number P, the probability Harry needs to be below, and an integer N (0 < N ≤ 100), the number of banks he has plans for. Then follow N lines, where line j gives an integer Mj (0 < Mj ≤ 100) and a real number Pj . Bank j contains Mj millions, and the probability of getting caught from robbing it is Pj. A bank goes bankrupt if it is robbed, and you may assume that all probabilities are independent as the police have very low funds.
Output
For each case, print the case number and the maximum number of millions he can expect to get while the probability of getting caught is less than P.
Sample Input
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
Sample Output
Case 1: 2
Case 2: 4
Case 3: 6
题意:哈利波特毕业了,由于没找到工作,他想去抢银行,他的两个基友为他算了一卦,告诉他如果他被抓的概率小于或等于P,他就会很安全,否则就一定会被抓。
于是哈利波特去调查了一下,记录每个银行的存钱量和被抓的风险,要求你计算他最多能抢多少钱
先转化一下:改限制为不被抓的概率大于等于(1-P),再将这个问题转化为背包01问题
dp(i)代表抢i枚大钱不被抓的概率
dp (i)=max { dp ( i - a[j] ) *( 1- p[j] ) , dp[i] } (i--0~所有银行的钱,j遍历所有银行)
#include"iostream"
#include"cstdio"
#include"cstring"
using namespace std;
const int maxn=;
double dp[maxn*maxn],P,b[maxn];
int n,a[maxn],sum,ca=;
void Init()
{
cin>>P>>n;
sum=;
for(int i=;i<n;i++)
{
cin>>a[i]>>b[i];
sum+=a[i];
}
memset(dp,,sizeof(dp));
} void Work()
{
dp[]=;
for(int i=;i<n;i++)
{
for(int j=sum;j>=a[i];j--)
{
dp[j]=max(dp[j-a[i]]*(-b[i]),dp[j]);
}
}
} void Print()
{
cout<<"Case "<<ca++<<": ";
for(int i=sum;i>=;i--)
{
if(dp[i]>(-P))
{
cout<<i<<endl;
break;
}
}
} int main()
{
int T;
cin>>T;
while(T--)
{
Init();
Work();
Print();
}
return ;
}
集训第六周 数学概念与方法 概率 N题的更多相关文章
- 集训第六周 数学概念与方法 概率 F题
Submit Status Description Sometimes some mathematical results are hard to believe. One of the common ...
- 集训第六周 数学概念与方法 概率 数论 最大公约数 G题
Description There is a hill with n holes around. The holes are signed from 0 to n-1. A rabbit must h ...
- 集训第六周 数学概念与方法 数论 筛素数 H题
Description 小明对数的研究比较热爱,一谈到数,脑子里就涌现出好多数的问题,今天,小明想考考你对素数的认识. 问题是这样的:一个十进制数,如果是素数,而且它的各位数字和也是素数,则称之为“ ...
- 集训第六周 数学概念与方法 计数 排列 L题
Description 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了! 做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样. 话 ...
- 集训第六周 数学概念与方法 J题 数论,质因数分解
Description Tomorrow is contest day, Are you all ready? We have been training for 45 days, and all g ...
- 集训第六周 数学概念与方法 数论 线性方程 I题
Description The Sky is Sprite. The Birds is Fly in the Sky. The Wind is Wonderful. Blew Throw the Tr ...
- 集训第六周 数学概念与方法 UVA 11181 条件概率
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18546 题意:有n个人会去超市,其中只有r个人会买东西,每个人独自买东西的概 ...
- 集训第六周 数学概念与方法 UVA 11722 几何概型
---恢复内容开始--- http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31471 题意,两辆火车,分别会在[t1,t2],[ ...
- 集训第六周 古典概型 期望 D题 Discovering Gold 期望
Description You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell o ...
随机推荐
- (博弈论 高精度小数)51NOD 1185 威佐夫游戏 V2
有2堆石子.A B两个人轮流拿,A先拿.每次可以从一堆中取任意个或从2堆中取相同数量的石子,但不可不取.拿到最后1颗石子的人获胜.假设A B都非常聪明,拿石子的过程中不会出现失误.给出2堆石子的数量, ...
- JavaScript编程艺术-第6章(JavaScript美术馆改进版)代码
基于[第4章(JavaScript美术馆)代码]进行改进(***HTML与JS分离***) (*亲测可用) HTML: JS: CSS:
- .Net Framework Client Profile 和 .Net Framework的区别[转]
原文链接 VS2010默认是以.Net Framework Client Profile为生成环境的,如果需要更多的功能,应该调用.Net Framework.
- [转]为革命保护视力 --- 给 Visual Studio 换颜色
本文转自:http://www.cnblogs.com/stg609/p/3723968.html “为革命,保护视力,预防近视,眼保健操开始......” 这个应该是最老版本的眼保健操了,你听过? ...
- 聊聊mq中消息消费的几种方式
mq系列文章 对mq了解不是很多的,可以看一下下面两篇文章: 聊聊mq的使用场景 聊聊业务系统中投递消息到mq的几种方式 聊聊消息消费的几种方式 如何确保消息至少消费一次 如何保证消息消费的幂等性 本 ...
- 工厂方法模式及php实现
工厂方法模式: 工厂方法模式(Factory Method Pattern)又称为工厂模式,也叫虚拟构造器(Virtual Constructor)模式或者多态工厂(Polymorphic Facto ...
- Vue.js学习笔记--1.基础HTML和JS属性的使用
整理自官网教程 -- https://cn.vuejs.org/ 1. 在HTML文件底部引入Vue <script src="https://cdn.jsdelivr.net/npm ...
- javscript 导出html中的table到excel
<script language="JavaScript" type="text/javascript"> /* * 默认转换实现函数,如果需要其他 ...
- t-sql的楼梯:超越基本级别6:使用案例表达式和IIF函数
t-sql的楼梯:超越基本级别6:使用案例表达式和IIF函数 源自:Stairway to T-SQL: Beyond The Basics Level 6: Using the CASE Expre ...
- jquery日期控件+时分秒
因为项目需要,一些时间上的查询要精确的时分.先看下效果图吧. 所需要的js 跟css 文件 jsp://特别注意引入的先后顺序 <link rel="stylesheet" ...