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

 题意:
  给你p,n
  n个银行,给出每个银行可以抢的钱和 被抓的概率
  问你在被抢概率才不超过p情况下能最多抢多少钱
题解:
  01背包
  设定dp[i][j] 前i个抢j元的 最小被抓概率
  dp[i][j] = min(dp[i][j], dp[i-1][j-x] + (1-dp[i-1][j-x])*v[i]);
 

#include <cstdio>
#include <cstring>
#include <vector>
#include<iostream>
#include <algorithm>
using namespace std;
const int N = 1e2 + , M = 1e4 , mod = 1e9 + , inf = 2e9;
int T,n,x;
double dp[M+],f,p;
int main()
{
int cas = ;
scanf("%d",&T);
while(T--) {
for(int i=;i<=M;i++) dp[i] = -;
dp[] = ;
scanf("%lf%d",&p,&n);
for(int i=;i<=n;i++) {
scanf("%d%lf",&x,&f);
for(int j=M;j>=x;j--) {
if(dp[j-x]==-) continue;
///cout<<j<<endl;
if(dp[j]==-1) dp[j] = dp[j-x] + (1.0-dp[j-x])*f;
else dp[j] = min(dp[j],dp[j-x] + (1.0-dp[j-x])*f);
}
}
int ans = ;///cout<<dp[M]<<endl;
for(int i=0;i<=M;i++) {
if(dp[i]!=-1&&dp[i] <= p) ans = i;
}
printf("Case %d: %d\n",cas++,ans);
}
}

LightOJ 1079 Just another Robbery 概率背包的更多相关文章

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

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

  2. LightOJ 1079 Just another Robbery (01背包)

    题意:给定一个人抢劫每个银行的被抓的概率和该银行的钱数,问你在他在不被抓的情况下,能抢劫的最多数量. 析:01背包,用钱数作背包容量,dp[j] = max(dp[j], dp[j-a[i] * (1 ...

  3. LightOJ 1079 Just another Robbery (01背包)

    题目链接 题意:Harry Potter要去抢银行(wtf???),有n个银行,对于每个银行,抢的话,能抢到Mi单位的钱,并有pi的概率被抓到.在各个银行被抓到是独立事件.总的被抓到的概率不能超过P. ...

  4. LightOJ-1079-Just another Robbery(概率, 背包)

    链接: https://vjudge.net/problem/LightOJ-1079#author=feng990608 题意: As Harry Potter series is over, Ha ...

  5. lightoj 1079 Just another Robbery

    题意:给出银行的个数和被抓概率上限.在给出每个银行的钱和抢劫这个银行被抓的概率.求不超过被抓概率上线能抢劫到最多的钱. dp题,转移方程 dp[i][j] = min(dp[i-1][j] , dp[ ...

  6. (概率 01背包) Just another Robbery -- LightOJ -- 1079

    http://lightoj.com/volume_showproblem.php?problem=1079 Just another Robbery As Harry Potter series i ...

  7. 1079 - Just another Robbery

    1079 - Just another Robbery   PDF (English) Statistics Forum Time Limit: 4 second(s) Memory Limit: 3 ...

  8. LightOJ - 1079 概率dp

    题意:n个银行,每个有价值和被抓概率,要求找被抓概率不超过p的最大价值 题解:dp[i][j]表示前i个取j价值的所需最小概率,01背包处理,转移方程dp[i][j]=min(dp[i-1][j],d ...

  9. hdu 2955 Robberies(概率背包)

    Robberies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

随机推荐

  1. CSS+JS实现兼容性很好的无限级下拉菜单

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DT ...

  2. IE浏览器模式设置

    文件兼容性用于定义让IE如何编译你的网页.此文件解释文件兼容性,如何指定你网站的文件兼容性模式以及如何判断一个网页该使用的文件模式. 前言 为了帮助确保你的网页在所有未来的IE版本都有一致的外观,IE ...

  3. linux下可以禁用的一些服务

    linux下多软件/多脚本之间的配合: 包括做好 “实体”和“配置”两个方面的事情 “实体”是指实实在在的脚本文件,服务脚本: “配置”是指其他与之交互的.协同工作的软件.脚本,要进行适当的配置,告知 ...

  4. git常见问题解决办法

    1,git status乱码 git config --global core.quotepath false 执行完后再使用时,就显示正常了

  5. R-squared是什么意思

    在回归分析中,R-squared值应该为多大? 就像经常被问到,在回归分析中,R平方应该为多大才表示回归模型是好的?我经常能够听到这类问题,在没回答这个问题之前,我会解释如 何来解释R平方值,我也会阐 ...

  6. ADF成长记1--认识ADF

    2014-07-08 近段时间由于公司项目需要,开始接触Oracle ADF.都说有事没事,上百度,但是对于IT技术而言,上百度还真是不一定好使,至于谷歌嘛,很不巧的进不去了.不过网上ADF的资料当真 ...

  7. Android Bitmap 全面解析(四)图片处理效果对比 ...

    对比对象: UIL Volley 官方教程中的方法(此系列教程一里介绍的,ImageLoader的处理方法和官方的差不多) -------------------------------------- ...

  8. [BZOJ1789][BZOJ1830][Ahoi2008]Necklace Y型项链

    [BZOJ1789][BZOJ1830][Ahoi2008]Necklace Y型项链 试题描述 欢乐岛上众多新奇的游乐项目让小可可他们玩的非常开心.现在他们正在玩比赛串项链的游戏,谁串的最快就能得到 ...

  9. HDU 1708 简单dp问题 Fibonacci String

    Fibonacci String Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  10. zookeeper 配置详解

    http://blog.csdn.net/shenlan211314/article/details/6185176  因博主原创,所以不能转载 下面是更为详细的配置说明: 前面两篇文章介绍了Zook ...