LightOJ-1079-Just another Robbery(概率, 背包)
链接:
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(概率, 背包)的更多相关文章
- LightOJ 1079 Just another Robbery 概率背包
Description As Harry Potter series is over, Harry has no job. Since he wants to make quick money, (h ...
- 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
题意:给出银行的个数和被抓概率上限.在给出每个银行的钱和抢劫这个银行被抓的概率.求不超过被抓概率上线能抢劫到最多的钱. 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 ...
随机推荐
- Leetcode之动态规划(DP)专题-413. 等差数列划分(Arithmetic Slices)
Leetcode之动态规划(DP)专题-413. 等差数列划分(Arithmetic Slices) 如果一个数列至少有三个元素,并且任意两个相邻元素之差相同,则称该数列为等差数列. 例如,以下数列为 ...
- numpy的concatenate实现矩阵拼接
concatenate() 我们先来介绍最全能的concatenate()函数,后面的几个函数其实都可以用concatenate()函数来进行等价操作. concatenate()函数根据指定的维度, ...
- 利用docker搭建本地私有镜像仓库
主机名 角色 sht-sgmhadoopcm-01 Docker Repository sht-sgmhadoopnn-01 Docker Client 1. 在两台节点分别安装docker http ...
- sql sever 两数据表差异比较EXCEPT、INTERSECT
1.概念: EXCEPT主要是用来获取两个结果集的差:两个结果用EXCEPT链接,返回第一个结果集不在第二个结果集中的数据. INTERSECT主要是用来获取两个结果集的交集:两个结果用INTERSE ...
- Oracle数据块
最小单位的输入\输出 数据块由操作系统中的一个或多个块组成 数据库是表空间的基本单位 DB_BLOCK_SIZE 查看 Oracle 块的大小语句: SQL> show parameter db ...
- int与Integer的一个小区别
int不能为空,而Integer可以赋空值
- 非旋(fhq)Treap小记
前置知识:二叉搜索树 以下摘自 ↑: 二叉搜索树每次操作访问O(深度)个节点. 在刻意构造的数据中,树的形态会被卡成一条链,于是复杂度爆炸 它的复杂度与直接暴力删除类似. 但二叉搜索树扩展性强.更复杂 ...
- %300为0的个数(牛客第四场)-- number
题意: 给你一串数,问你如题. 思路: 我不是这样的作法,从后往前,先取00,再算%3==0的个数,往前推的时候有递推关系: #define IOS ios_base::sync_with_stdio ...
- AppCan IDE中有时格式化代码后,代码就运行不了了。
AppCan IDE中有时格式化代码后,代码就运行不了了.
- Python模拟进度条
import time for i in range(0,101,2) time.sleep(0.2) num = i // 2 per = '\r %s %% : %s'%(i,'*'*num) p ...