链接:

https://vjudge.net/problem/LightOJ-1079#author=feng990608

题意:

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.

思路:

概率,把小于最大值,变成大于最小概率,用背包搞一下就行,之前刷背包刷到过,现在居然忘了..

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
//#include <memory.h>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <stack>
#include <string>
#include <assert.h>
#include <iomanip>
#define MINF 0x3f3f3f3f
using namespace std;
typedef long long LL; double Dp[100010], P[110];
int M[110];
int n; int main()
{
int t, cnt = 0;
scanf("%d", &t);
while (t--)
{
memset(Dp, 0, sizeof(Dp));
double p;
int sum = 0;
scanf("%lf%d", &p, &n);
for (int i = 1;i <= n;i++)
scanf("%d%lf", &M[i], &P[i]), sum += M[i];
p = 1-p;
Dp[0] = 1.0;
for (int i = 1;i <= n;i++)
{
for (int j = sum;j >= M[i];j--)
Dp[j] = max(Dp[j], Dp[j-M[i]]*(1-P[i]));
}
int res = 0;
for (int i = sum;i >= 0;i--)
if (Dp[i] >= p)
{
res = i;
break;
}
printf("Case %d: %d\n", ++cnt, res);
} return 0;
}

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

  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 —— 概率、背包

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

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

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

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

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

  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. Linux目录权限管理

    Linux目录权限管理   实验目标: 通过本实验掌握centos7/rhel7目录权限的管理.包括配置目录的所属组.SGID.读/写/执行权限等. 实验步骤: 1.创建目录/home/instruc ...

  2. ORACLE 左连接 右连接 内连接 外连接 全连接 五中表连接方式

    1.左连接 :left join 2.右连接:right join 3.内连接:inner join 4.外连接:outer join 5.全连接:full join

  3. 【神经网络与深度学习】如何在Caffe中配置每一个层的结构

    如何在Caffe中配置每一个层的结构 最近刚在电脑上装好Caffe,由于神经网络中有不同的层结构,不同类型的层又有不同的参数,所有就根据Caffe官网的说明文档做了一个简单的总结. 1. Vision ...

  4. mysql——查询语句——单表查询——(概念)

    一.基本查询语句 select的基本语法格式如下: select 属性列表 from 表名和视图列表 [ where 条件表达式1 ] [ group by 属性名1 [ having 条件表达式2 ...

  5. C#连接oracle数据库报错:OCIEnvCreate 失败,返回代码为 -1,但错误消息文本不可用

    原因大概是OracleOraDb11g_home1TNSListener服务没启动的原因 步骤一.停止并重新启动OracleOraDb11g_home1TNSListener服务,试一下是否可行. 如 ...

  6. sql server备份损坏

    sql server备份损坏 转自:https://www.cnblogs.com/zhijianliutang/p/4080916.html 1.备份文件和数据库放在同一个(或一组)的物理磁盘上.磁 ...

  7. 链表--笔记--数据结构(C++版)王红梅--自我思路整理与梳理

    看到这篇文的很多人大概都知道链表是个什么玩意了.简单说就是一个又一个的指针,指针之间用指针连接起来. 本文的阅读   适合有c++基础的人群 以下: 这叫做一个结点. 这就是一个链表.我们主要使用的是 ...

  8. 初步了解autoencoder

    初步了解autoencoder 学习自莫烦python 什么是autoencoder? 自编码(autoencoder)是一种神经网络的形式. 例子:一张图片->对其进行打码->最后再将其 ...

  9. 【pytorch】学习笔记(一)-张量

    pytorch入门 什么是pytorch PyTorch 是一个基于 Python 的科学计算包,主要定位两类人群: NumPy 的替代品,可以利用 GPU 的性能进行计算. 深度学习研究平台拥有足够 ...

  10. 树状数组+二维前缀和(A.The beautiful values of the palace)--The Preliminary Contest for ICPC Asia Nanjing 2019

    题意: 给你螺旋型的矩阵,告诉你那几个点有值,问你某一个矩阵区间的和是多少. 思路: 以后记住:二维前缀和sort+树状数组就行了!!!. #define IOS ios_base::sync_wit ...