题意:给定一个人抢劫每个银行的被抓的概率和该银行的钱数,问你在他在不被抓的情况下,能抢劫的最多数量。

析:01背包,用钱数作背包容量,dp[j] = max(dp[j], dp[j-a[i] * (1.0 - pp[i])),dp[i] 表示不被抓的最大概率,在能抢劫到 i 个钱。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e16;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e4 + 10;
const int mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
} double dp[maxn];
int a[maxn];
double pp[maxn]; int main(){
int T; cin >> T;
for(int kase = 1; kase <= T; ++kase){
double p;
scanf("%lf %d", &p, &n);
p = 1.0 - p;
memset(dp, 0, sizeof dp);
m = 0;
for(int i = 1; i <= n; ++i){
scanf("%d %lf", a+i, pp+i);
m += a[i];
}
dp[0] = 1.0;
for(int i = 1; i <= n; ++i)
for(int j = m; j >= a[i]; --j)
dp[j] = max(dp[j], dp[j-a[i]] * (1.0 - pp[i])); int ans = 0;
for(int i = m; i; --i) if(dp[i] >= p){
ans = i; break;
}
printf("Case %d: %d\n", kase, ans);
}
return 0;
}

  

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

  1. LightOJ 1079 Just another Robbery 概率背包

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

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

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

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

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

  4. lightoj 1079 Just another Robbery

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

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

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

  6. lightoj 1125【01背包变性】

    题意: 从n个数里选出m个来,还要使得这m个数之和被d整除. 给一个n和q,再给n个数,再给q个询问,每个询问包含两个数,d,m; 对于每个case输出每个q个询问的可行的方案数. 思路: 每个数只能 ...

  7. 1079 - Just another Robbery

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

  8. hdu 2955 01背包

    http://acm.hdu.edu.cn/showproblem.php?pid=2955 如果认为:1-P是背包的容量,n是物品的个数,sum是所有物品的总价值,条件就是装入背包的物品的体积和不能 ...

  9. Robberies(简单的01背包 HDU2955)

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

随机推荐

  1. iconfont阿里字体图标的使用方法

    我们在做web项目的时候,之前比较常用的是bootstrap,所以使用font awesome字体图标比较多,无意中在一个项目中接触到了iconfont,发现想要的什么图标都有,还可以自定义图标,非常 ...

  2. ssh面试题2

    1. BeanFactory的作用是什么? [中] BeanFactory是配置.创建.管理bean的容器,有时候也称为bean上下文.Bean与bean的依赖关系,也是由BeanFactory负责维 ...

  3. 【转】c# 判断指定文件是否存在

    private void button2_Click(object sender, EventArgs e) { if (File.Exists(@"E:\exists.txt") ...

  4. nginx学习资源

    在了解nginx的时候 看到的一些资源: https://www.cnblogs.com/EdwinChan/p/8350984.html http://tengine.taobao.org/book ...

  5. unittest框架,调用函数类 和 调用函数外的 方法

  6. 【转】JMeter基础之——录制脚本

    Jmeter 是一个非常流行的性能测试工具,虽然与LoadRunner相比有很多不足,比如:它结果分析能力没有LoadRunner详细:很它的优点也有很多: ● 开源,他是一款开源的免费软件,使用它你 ...

  7. Git使用点滴记录: You have no permission to access this repo.

    代码托管在https://coding.net上面,之前Git用https的方式都好好的,没有出什么问题.结果今天git pull代码的时候一直提示以下信息: remote: Coding.net T ...

  8. python开发函数进阶:生成器表达式&各种推导式

    一,生成器表达式 #生成器表达式比列表解析更省内存,因为惰性运算 #!/usr/bin/env python #_*_coding:utf-8_*_ new_2 = (i*i for i in ran ...

  9. SDRAM 之时序收敛(学习了特权老师)

    到现在我还是不太理解SDRAM的时序设置,但是可能蒙对了.(呵呵) 开发环境: quartus II 13.0   板子: DE2 EP2C35F672C6N 时序约束step 1:create cl ...

  10. 固态硬盘安装win7系统问题。

    可能出现:安装程序无法创建新的系统分区 出现这个错误后, 1.可以先尝试把固态硬盘插在硬盘的第一个硬盘口上,然后安装系统时拔掉U盘刷新再点击安装. 2.可以尝试在PE下直接安装系统. 如果上两个方法都 ...