链接:

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. Foxmail:导入联系人

    打开“Foxmail”之后,如下图所示: 接下来,在左下角找到箭头指示的位置处,点击此处: 接下来,在邮箱的右上角找到如图所示的位置,鼠标点击此处: 点击之后,如下图所示,找到“导入”: 点击“导入& ...

  2. 应用安全 - JavaScript - 框架 - Jquery - 漏洞 - 汇总

    jQuery CVE-2019-11358 Date 类型 原型污染 影响范围 CVE-2015-9251  Date 类型跨站 影响范围<jQuery 3.0.0

  3. 海量数据和高并发下的 Redis 业务优化实践

    本文内容是我在 6 月 23 日参加的深圳 GIAC 技术大会上演讲的文字稿. 观众朋友们,我是来自掌阅的工程师钱文品,掘金小册<Redis 深度历险>的作者.今天我带来的是分享主题是:R ...

  4. POJ - 3469 Dual Core CPU (最小割)

    (点击此处查看原题) 题意介绍 在一个由核A和核B组成的双核CPU上执行N个任务,任务i在核A上执行,花费Ai,在核B上执行,花费为Bi,而某两个任务之间可能需要进数据交互,如果两个任务在同一个核上执 ...

  5. vue cli3项目发布在apache www/vue目录下并配置history路由

    注意:vue项目打包后默认是指向服务器的根路径(比如apache默认www目录是根路径,当然也可以修改),这种情况不需要做路径的配置,只需要做history配置,如果不是发布到根路径而是www/vue ...

  6. 15、R语言聚类树的绘图原理

    聚类广泛用于数据分析.去年研究了一下R语言聚类树的绘图原理.以芯片分析为例,我们来给一些样品做聚类分析.聚类的方法有很多种,我们选择Pearson距离.ward方法. 选择的样品有: "GS ...

  7. python网络爬虫(7)爬取静态数据详解

    目的 爬取http://seputu.com/数据并存储csv文件 导入库 lxml用于解析解析网页HTML等源码,提取数据.一些参考:https://www.cnblogs.com/zhangxin ...

  8. pytorch简单框架

    网络搭建: mynn.py: import torchfrom torch import nnclass mynn(nn.Module): def __init__(self): super(mynn ...

  9. Ubuntu与centos的区别小用法

    给root设置密码 更新软件下载的地址 安装指令apt 使用ssh登录Ubuntu 使用ssh登录Ubuntu必须注意的地方,要先配置 sudo vi /etc/ssh/sshd_config 找到: ...

  10. ueditor 后端配置项没有正常加载,上传插件不能正常使用 UTF8 PHP

    修改config.json 文件,用DW软件打开,修改好后,保存 若用记事本打开的话修改后保存,无法加载