N - 概率

Time Limit:4000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu

Submit Status

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题的更多相关文章

  1. 集训第六周 数学概念与方法 概率 F题

    Submit Status Description Sometimes some mathematical results are hard to believe. One of the common ...

  2. 集训第六周 数学概念与方法 概率 数论 最大公约数 G题

    Description There is a hill with n holes around. The holes are signed from 0 to n-1. A rabbit must h ...

  3. 集训第六周 数学概念与方法 数论 筛素数 H题

    Description 小明对数的研究比较热爱,一谈到数,脑子里就涌现出好多数的问题,今天,小明想考考你对素数的认识.  问题是这样的:一个十进制数,如果是素数,而且它的各位数字和也是素数,则称之为“ ...

  4. 集训第六周 数学概念与方法 计数 排列 L题

    Description 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了! 做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样. 话 ...

  5. 集训第六周 数学概念与方法 J题 数论,质因数分解

    Description Tomorrow is contest day, Are you all ready? We have been training for 45 days, and all g ...

  6. 集训第六周 数学概念与方法 数论 线性方程 I题

    Description The Sky is Sprite. The Birds is Fly in the Sky. The Wind is Wonderful. Blew Throw the Tr ...

  7. 集训第六周 数学概念与方法 UVA 11181 条件概率

    http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18546 题意:有n个人会去超市,其中只有r个人会买东西,每个人独自买东西的概 ...

  8. 集训第六周 数学概念与方法 UVA 11722 几何概型

    ---恢复内容开始--- http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31471 题意,两辆火车,分别会在[t1,t2],[ ...

  9. 集训第六周 古典概型 期望 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 ...

随机推荐

  1. 《Google软件测试之道》心得笔记1

    Google软件测试介绍 把开发和测试融合在一起——开发和测试必须同时展开 开发人员自己要对自己写的代码负责,比专职的测试人员更适合做测试工作. 测试开发工程师SET 对于Google拥有很少量的测试 ...

  2. poj 2349 Arctic Network(最小生成树的第k大边证明)

    题目链接: http://poj.org/problem?id=2349 题目大意: 有n个警戒部队,现在要把这n个警戒部队编入一个通信网络, 有两种方式链接警戒部队:1,用卫星信道可以链接无穷远的部 ...

  3. _bzoj1798 [Ahoi2009]Seq 维护序列seq【线段树 lazy tag】

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1798 注意,应保证当前节点维护的值是正确的,lazy tag只是一个下传标记,在下传时应即时 ...

  4. django中实现websocket

    一.Websockets介绍 随着互联网的发展,传统的HTTP协议已经很难满足Web应用日益复杂的需求了.近年来,随着HTML5的诞生,WebSocket协议被提出,它实现了浏览器与服务器的全双工通信 ...

  5. ASP.NET中图片验证码与js获取验证码的值

    现在的程序中,为了防止用户恶意点击,我们一般都会加上验证,现在比较普遍的是加上图片验证码或者手机短信验证.验证码一般都是防机器不防人,有效的防止了恶意点击. 那么在webform中如何生成动态的图片验 ...

  6. WinForm 对话框,流

    private void button1_Click(object sender, EventArgs e) { //显示颜色选择器 colorDialog1.ShowDialog(); //把取到的 ...

  7. [BZOJ1004][HNOI2008]Cards 群论+置换群+DP

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1004 首先贴几个群论相关定义和引理. 群:G是一个集合,*是定义在这个集合上的一个运算. ...

  8. 表单里的button默认是submit类型

    今天很坑爹,周六一大早加班开始码代码,本来想做数据加密测试,于是乎用tp框架搭建了一个应用环境,二话不说,开始码码. 但,今天一大早就栽坑!直到同事喊吃饭还在坑里出不来!吃完饭继续码,最后码的我想哭o ...

  9. php自动加载函数

    含义:将函数注册到SPL __autoload函数栈中.如果该栈中的函数尚未激活,则激活它们. 先看__autoload 函数 printit.class.php <?php class PRI ...

  10. .net 操作xml --移除注释节点

    /// <summary> /// xml字符串转xml文档 忽略注释信息 /// </summary> /// <param name="sXml" ...