集训第六周 数学概念与方法 概率 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 ...
随机推荐
- 有了Git这些操作,我再也不怕开发了!
Git 是什么? Git 是一个分布式的代码管理容器,本地和远端都保有一份相同的代码. Git 仓库主要是由是三部分组成:本地代码,缓存区,提交历史. Git 有哪些常规操作? Git的常规操作你了解 ...
- Java-String 类的常用方法
Java 中 String 类的常用方法 Ⅰ String 类提供了许多用来处理字符串的方法,例如,获取字符串长度.对字符串进行截取.将字符串转换为大写或小写.字符串分割等,下面我们就来领略它的强大之 ...
- win7 右键菜单残影 消除方法
1. 治标法: 右键桌面->更改分辨率 随便换一个分辨率再还原就OK了! 2. 根治法: 我的电脑-> 属性 ->高级选项-> 高级-> 设置-> 自定义 不 ...
- Bootstrap简介及安装使用
Bootstrap 简介 什么是 Bootstrap? Bootstrap 是一个用于快速开发 Web 应用程序和网站的前端框架.Bootstrap 是基于 HTML.CSS.JAVASCRIPT 的 ...
- 枚举Enum通过int值或文本转为对应的枚举类型
1.数值转枚举 如果枚举类型继承了数值类型,可以直接强制转换 public enum SourceType : byte { YC = , TS = , QK = , ZQ = } //转换方式 ; ...
- "言官误国"
"言官误国" 之前读<明朝那些事儿>的时候,了解到了一个全新的概念,确切的说与之前的印象完全不符合的概念:言官.之前我印象中的言官都是魏征那样的人,为国为民.冒死直谏等 ...
- Elasticsearch--集群&时光之门和恢复控制
节点发现 启动一个Elasticsearch节点时,该节点会开始寻找具有相同集群名字并且可见的主节点.如果找到主节点,该节点加入一个已经组成了的集群:如果没有找到,该节点成为主节点(如果配置允许).形 ...
- 全志R58平台调通s5k5eya(RAW+MIPI)
全志R58平台调通s5k5eya(RAW+MIPI) 2017/5/31 10:30 版本:V1.1 1.前期使用的是s5k5eyx的ISP的固件/tuning 文件 Y:\s5k5eya_r58_d ...
- 微信小程序组件解读和分析:六、progress进度条
progress进度条组件说明: 进度条,就是表示事情当前完成到什么地步了,可以让用户视觉上感知事情的执行.progress进度条是微信小程序的组件,和HTML5的进度条progress类似. pro ...
- (转)Spring中的事务操作
http://blog.csdn.net/yerenyuan_pku/article/details/70024364 事务的回顾 什么是事务 事务是逻辑上的一组操作,组成这组操作的各个逻辑单元,要么 ...