1079 - Just another Robbery
Time Limit: 4 second(s) Memory Limit: 32 MB

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

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

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.0494which is greater than the given probability (0.04). That's why he has only option, just to rob rank 2.

题解:给你一个总概率p,再给你N个银行,里面有钱vi,被抓到的概率是pi,要使被抓住的概率小于p,也就是没被抓到的概率大于1-p就好了,总钱数当作背包的容量,概率当作背包的值;

代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
using namespace std;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
typedef long long LL;
#define mem(x,y) memset(x,y,sizeof(x))
#define PI(x) printf("%d",x)
#define PL(x) printf("%lld",x)
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define P_ printf(" ")
#define T_T while(T--)
const int MAXN=110;
struct Node{
double p;
int w;
friend bool operator < (Node a,Node b){
if(a.p<b.p)return true;
else return false;
}
};
double bag[10010];
Node dt[MAXN];
int main(){
int T,kase=0;
SI(T);
T_T{
double p;
int N;
scanf("%lf%d",&p,&N);
int sum=0;
for(int i=0;i<N;i++)scanf("%d%lf",&dt[i].w,&dt[i].p),sum+=dt[i].w;
sort(dt,dt+N);
mem(bag,0);bag[0]=1;
for(int i=0;i<N;i++){
for(int j=sum;j>=dt[i].w;j--)
bag[j]=max(bag[j],bag[j-dt[i].w]*(1-dt[i].p));
}
for(int i=sum;i>=0;i--){
if(bag[i]>1-p){
printf("Case %d: %d\n",++kase,i);break;
}
}
}
return 0;
}

  

Just another Robbery(背包)的更多相关文章

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

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

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

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

  3. LightOJ 1079 Just another Robbery 概率背包

    Description As Harry Potter series is over, Harry has no job. Since he wants to make quick money, (h ...

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

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

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

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

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

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

  7. Hdu 2955 Robberies 0/1背包

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

  8. HDU2955 背包DP

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

  9. HDU 2955 01背包(思维)

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

随机推荐

  1. JavaSE复习日记 : 接口

    /* * 接口 * 引用数据类型: * 类,接口,数组; * * 接口是一种引用数据类型,可以看作是一个特殊的类,它存在的目的是为了解决没有多重继承引起的功能弱的问题而设计的,一个类只能有一个父类,但 ...

  2. ping时不知道ping那个Ip的解决办法

    利用命令:nslookup Windows+R键,输入CMD,输入命令nslookup www.baidu.com OK!这得在联网情况下,如果本身nslookup就不行的话,可不可以认为网络就不好使 ...

  3. Apache与Nginx优缺点比较

    本文来源:收集.整理自互联网 1.nginx相对于apache的优点:  轻量级,同样起web 服务,比apache 占用更少的内存及资源  抗并发,nginx 处理请求是异步非阻塞的,而apache ...

  4. ubuntu中查找软件的安装位置

    ubuntu中的软件可通过图形界面的软件中心安装,也可以通过命令行apt-get install安装.但是安装后的软件在哪个位置呢?这点跟windows环境下安装软件的路径选择不一样.ubuntu中可 ...

  5. jdk outMemory内存溢出

    参数的含义: -vmargs -Xms256M -Xmx768M -Xss256k -XX:PermSize=256M -XX:MaxPermSize=768M -vmargs 说明后面是vm的参数 ...

  6. Minix

    [1]  MINIX是一种基于微内核架构的类UNIX计算机操作系统,由Andrew S. Tanenbaum发明.MINIX最初发布于1987年,开放全部源代码给大学教学和研究工作.2000年重新改为 ...

  7. Java 初始化的个人理解

    先说明一下由来吧,下面是同学的一道笔试题,以前感觉对java初始化也是了解一二的,结果,看到这题泪奔了,不会...上网查,自己添加println,总算是能把自己讲明吧了,不知理解的对不对,先记录下吧, ...

  8. BlueTooth的EDR是什么

    EDR 即Enhanced data rate,是蓝牙技术中增强速率的缩写,其特色是大大提高了蓝牙技术的数据传输速率,达到了2.1Mbps ,是目前蓝牙技术的三倍.因此除了可获得更稳定的音频流传送的更 ...

  9. javascript简单对象创建

    由于javascript中定义了一个函数就相当于定义了一个类,我们当然可以创建一个这个类的对象. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 ...

  10. java面向对象编程(类、对象)

    一.面向对象编程概述面向对象编程(Object  Oriented  Programming,缩写为OOP)是当今最流行的程序设计技术,它具有代码易于维护.可扩展性好和代码可常用等优点.面向对象的设计 ...