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. 使用Docker Compose编排微服务

    一般微服务架构会包含若干个微服务,而每个微服务可以有多个实例,如果每个微服务都有手动启停,那么效率就很低.维护量比较大. 所以我们可以使用Docker Compose来轻松.高效地管理容器. 一.安装 ...

  2. 【css】如何实现环形进度条

    最近团队的童鞋接到了一个有关环形进度条的需求,想要还原一个native的沿环轨迹渐变进度条的效果,看到这个效果的时候,笔者陷入了沉思.. 环形进度条的效果,最先想到的就是使用CSS利用两个半圆的hac ...

  3. C# System.IO 文件流输入输出

    一.读写文本文件 可以用fileStream来读写文本文件,但是FileStream是通过字节形式来读写数据的,要把字节数据转换为文本,要自己处理编码转换. 对于文本文件的读写,通常用 StreamR ...

  4. Android偏好设置(7)自定义Preference,和PreferenceDialog

    Building a Custom Preference The Android framework includes a variety of Preference subclasses that ...

  5. Cenos7 切换单用户模式

    CentOS 7在进入单用户的时候和6.x做了很多改变,下面让我们来看看如何进入单用户. 1.重启服务器,在选择内核界面使用上下箭头移动 2.选择内核并按“e” 3.修改参数 将rhgb quiet ...

  6. [转]MySQL游标的使用

    转自:http://www.cnblogs.com/sk-net/archive/2011/09/07/2170224.html 以下的文章主要介绍的是MySQL游标的使用笔记,其可以用在存储过程的S ...

  7. android开发学习——This support library should not use a different version

    http://blog.csdn.net/mvpstevenlin/article/details/55209966 完美解决系列

  8. .net 字符串和JSON格式的互换

    近期又做了个问卷调查,问卷调查一次性要保存一二十个题目和答案!所以嘞,博主为了偷懒,就直接把答卷内容保存成了Json格式! 好处当然是很多啦! 只需一个字段就能保存整个答卷的内容! 想想都刺激!哈哈~ ...

  9. Tomcat源码分析----eclipse中搭建源码环境

    前提:JDK,至少1.7,ant,要设置ANT_HOME环境变量,需要再classpath中增加ant的lib目录,在path变量中增加ant的bin目录 1.官网下载tomcat源码包:apache ...

  10. 公众号如何获取已关注用户的unionid的问题

    避免误导,先加一句:首先,得公众号绑定开放平台 这个问题困扰了我一早上,我尝试了很多次获取unionid都失败. 微信的开发文档上有说: 关于特殊场景下的静默授权 1.上面已经提到,对于以snsapi ...