题干:

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 probability P 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

Note

For the first case, if he wants to rob bank 1 and 2, then the probability of getting caught is 0.02 + (1 - 0.02) * .03 = 0.0494 which is greater than the given probability (0.04). That's why he has only option, just to rob rank 2.

题目大意:

有n个银行,每个银行有v[i]的钱,和被抓住的概率p[i]。你要按一定顺序去抢,要求你被抓住的概率小于等于P,你最多能获得多少钱。

解题报告:

首先不难证明,假设你选择了其中某num个银行,那么与选择的银行的顺序无关。证明如下:(假设你选择了第i个和的第j个)

考虑被抓的概率:,所以是等效的。

或者考虑不被抓的概率:,所以是等效的。

设定状态dp[i][j]代表前i个银行,得到了j块钱但是不被抓到最大概率。(其实设置最小概率应该也可以,但是转移的时候不是很好写。)

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define F first
#define S second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 10000 + 5;
double dp[205][MAX],P,p[205];
int n,v[205];
int main()
{int t,iCase=0;cin>>t;while(t--) {scanf("%lf%d",&P,&n);int sum = 0;for(int i = 1; i<=n; i++) scanf("%d%lf",&v[i],&p[i]),sum += v[i];for(int i = 1; i<=n; i++) {for(int j = 0; j<=sum; j++) dp[i][j]=0;}dp[0][0]=1;for(int i = 1; i<=n; i++) {for(int j = 0; j<=sum; j++) {dp[i][j] = dp[i-1][j];if(j >= v[i]) dp[i][j] = max(dp[i][j],dp[i-1][j-v[i]]*(1-p[i]));}}int ans = 0 ;for(int i = 0; i<=sum; i++) {if(dp[n][i] >= 1-P) ans = i;}printf("Case %d: %d\n",++iCase,ans);}return 0 ;
}

【LightOJ - 1079】Just another Robbery(概率dp,概率背包)相关推荐

  1. LightOJ 1079 Just another Robbery

    题目:LightOJ 1079 Just another Robbery 这个题挺有意思的,虽然也算得上是水吧-- 01背包是模板,但是这是一个涉及概率的问题,概率这个部分要学习一下. 下面的代码求的 ...

  2. LightOJ 1079 Just another Robbery【概率DP】

    题目: As Harry Potter series is over, Harry has no job. Since he wants to make quick money, (he wants ...

  3. LightOJ 1079 Just another Robbery (概率dp+背包)

    题意:有n家银行,每家银行都有一定数量的钱和被抓概率,给出自己被抓概率的上限,求能获得最多的钱. 题解:概率dp+背包 用dp[]dp[]dp[]表示获得这么多钱被抓的概率.获得同等钱的概率要尽可能小 ...

  4. LightOJ - 1079 Just another Robbery —— 概率、背包

    题目链接:https://vjudge.net/problem/LightOJ-1079 1079 - Just another Robbery     PDF (English) Statistic ...

  5. LightOJ 1079 Just another Robbery

    http://lightoj.com/volume_showproblem.php?problem=1079 这道题搞了挺久的...菜哭,本来想直接贪心用性价比最高的,结果过不了样例... 重新看了下 ...

  6. 动态规划 —— 概率 DP 与期望 DP

    [概述] 由于概率和期望具有线性性质,使得可以在概率和期望之间建立一定的递推关系,这样就可以通过动态规划来解决一些概率问题,例如概率和期望的最值问题就常常使用概率 DP.期望 DP 来解决. 与其他的 ...

  7. Discovering Gold LightOJ - 1030[概率dp或者记忆化搜索]

    题目大意:有一个[1,n][1,n][1,n]的数轴,数轴上的每个对应位置上都有金矿,你初始位置是1,然后你每次都会投色子决定你下一步跳到哪里,如果你跳出了nnn,那么你就要重新投.问你跳到nnn的时 ...

  8. LightOJ 1395 A Dangerous Maze (II) (概率dp)

    题意:给出n扇门,每扇门都给出一个数x,若为正数,则表示在x时间后走出迷宫,若为负数,则表示在x时间后回到起点,你会记得最后k扇你走过的门(不会再走),求最后的期望时间. 题解:概率dp 这题的进阶版 ...

  9. 01背包+概率dp Just another Robbery 抢银行

    题意:有n各个银行,每个银行有v[ i ]的钱并且有x [ i ] 的被抓住啊概率,如果被抓概率<=p,那么他是安全的,求他期望的最大钱数. 输入 3    //3组 0.04 3 1 0.02 ...

  10. 2018.09.01 poj3071Football(概率dp+二进制找规律)

    传送门 概率dp简单题. 设f[i][j]表示前i轮j获胜的概率. 如果j,k能够刚好在第i轮相遇,找规律可以发现j,k满足: (j−1)>>(i−1)(j−1)>>(i−1) ...

最新文章

  1. C++11中头文件thread的使用
  2. Smartform 动态打印选择屏幕上传的图片
  3. 在html中加动画效果,html5中css3新添加的动画效果
  4. nginx1.11.*版本追加安装sticky模块出现问题解决方法
  5. .NET Core 下使用 gRPC
  6. 乡镇上那些卖散白酒的一天不见几个人买,为什么不关店?
  7. SpringBoot之json转java实体类
  8. matlab匿名函数求导,MATLAB匿名函数和函数句柄
  9. js实现数字转化为大写金额——js技能提升
  10. java毕业设计社区食堂供餐源码+lw文档+mybatis+系统+mysql数据库+调试
  11. 一刹那,是幡然悔悟的一刹那
  12. python计算斜率以及给定一组点两两求斜率
  13. 利用计算机本地文档重装系统,电脑如何用本地模式重装win10
  14. error: C2338: Type is not registered, please use the Q_DECLARE_METATYPE macro to make it known to Qt
  15. 注册jar包为windows服务
  16. 性能测试:一个完整的性能测试过程
  17. 最大熵模型的特征函数及约束条件
  18. 电压跟随器的使用方法
  19. Apache顶级项目Ambari正式宣告退役!
  20. Cypress-should()常见断言

热门文章

  1. [BUGKU][CTF][Reverse][2020] Reverse writeup 1-7 暂时肝不动了
  2. [Leetcode][第785题][JAVA][判断二分图][BFS][DFS]
  3. POJ 1703 Find them, Catch them 种类并查集
  4. mysql定时增量备份_Mysql日常自动备份和增量备份脚本
  5. 苹果笔记本电脑好用吗_苹果新品发布会消息汇总(8月25日)
  6. 1526B. I Hate 1111
  7. html文档php 取mac地址_cpu序列号_硬盘序列号,用vbs脚本获取网卡MAC,CPUID,硬盘序列号的实现代码...
  8. c语言编程怎么实现替换,使用C语言实现字符串中子字符串的替换
  9. php索引数组相等,php二维数组中子数组的某一键相等,其余键值求和
  10. python操作sqlite3 导入csv文件_[转载]SQLite 3导入导出成txt或csv操作