LightOJ 1079 Just another Robbery 概率背包
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
#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 概率背包的更多相关文章
- LightOJ - 1079 Just another Robbery —— 概率、背包
题目链接:https://vjudge.net/problem/LightOJ-1079 1079 - Just another Robbery PDF (English) Statistics ...
- LightOJ 1079 Just another Robbery (01背包)
题意:给定一个人抢劫每个银行的被抓的概率和该银行的钱数,问你在他在不被抓的情况下,能抢劫的最多数量. 析:01背包,用钱数作背包容量,dp[j] = max(dp[j], dp[j-a[i] * (1 ...
- LightOJ 1079 Just another Robbery (01背包)
题目链接 题意:Harry Potter要去抢银行(wtf???),有n个银行,对于每个银行,抢的话,能抢到Mi单位的钱,并有pi的概率被抓到.在各个银行被抓到是独立事件.总的被抓到的概率不能超过P. ...
- LightOJ-1079-Just another Robbery(概率, 背包)
链接: https://vjudge.net/problem/LightOJ-1079#author=feng990608 题意: As Harry Potter series is over, Ha ...
- lightoj 1079 Just another Robbery
题意:给出银行的个数和被抓概率上限.在给出每个银行的钱和抢劫这个银行被抓的概率.求不超过被抓概率上线能抢劫到最多的钱. dp题,转移方程 dp[i][j] = min(dp[i-1][j] , dp[ ...
- (概率 01背包) Just another Robbery -- LightOJ -- 1079
http://lightoj.com/volume_showproblem.php?problem=1079 Just another Robbery As Harry Potter series i ...
- 1079 - Just another Robbery
1079 - Just another Robbery PDF (English) Statistics Forum Time Limit: 4 second(s) Memory Limit: 3 ...
- LightOJ - 1079 概率dp
题意:n个银行,每个有价值和被抓概率,要求找被抓概率不超过p的最大价值 题解:dp[i][j]表示前i个取j价值的所需最小概率,01背包处理,转移方程dp[i][j]=min(dp[i-1][j],d ...
- hdu 2955 Robberies(概率背包)
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
随机推荐
- DIV+CSS例子
DIV水平居中+垂直居中 #main_zone{ width:1190px; height:570px; background-color:#fff; margin:0 auto; /*左右居中*/ ...
- .NET中使用Memcached的相关资源整理
Memcached官方站点:http://www.danga.com/memcached/ Memcached Win32 1.2.6下载:http://code.jellycan.com/memca ...
- C#常用函数--通用篇
C#常用函数→通用篇转载地址→http://www.cnblogs.com/superfang/archive/2008/07/02/1233706.html以前我都是"原文地址" ...
- ubuntu下git输出的颜色变化
(这些文章都是从我的个人主页上粘贴过来的,大家也可以访问我的主页 www.iwangzheng.com) 11点进家门,感觉很温暖哦. 以下是如何在用git的时候清晰的看出关键字的方法. $ vim ...
- ruby实时查看日志
(文章是从我的个人主页上粘贴过来的, 大家也可以访问我的主页 www.iwangzheng.com) 在调试代码的时候,把日志文件打开,边操作边调试能很快帮助我们发现系统中存在的问题. $tail r ...
- LBP
参考:http://www.cnblogs.com/mikewolf2002/p/3438698.html
- SQL面试积累
以下题目都在MySQL上测试可行,有疏漏或有更优化的解决方法的话欢迎大家提出,我会持续更新的:) 有三个表,如果学生缺考,那么在成绩表中就不存在这个学生的这门课程成绩的记录,写一段SQL语句,检索出每 ...
- 新浪网易淘宝等IP地区信息查询开放API接口调用方法
通过IP地址获取对应的地区信息通常有两种方法:1)自己写程序,解析IP对应的地区信息,需要数据库.2)根据第三方提供的API查询获取地区信息. 第一种方法,参见文本<通过纯真IP数据库获取IP地 ...
- MVC 修饰标签
MVC中的修饰标签有很多用途.它以修饰标签形式应用在控制器或控制器中的动作上. 最先想到的就是AcceptVerbs标签,在创建的时候,如果导航到创建视图,但不创建,则: public ActionR ...
- 基础知识《四》---Java多线程学习总结
本文转载自51cto 一.线程的基本概念简单的说:线程就是一个程序里不同的执行路径,在同一个时间点上cpu只会有一个线程在执行,Java里的多线程是通过java.lang.Thread类来实现的,每个 ...