LightOj_1079 Just another Robbery
题意:
抢银行(这个背景最爱了), 有n家银行, 每家银行抢劫被抓的概率是p[i],你认为当你被抓的概率低于P的时候是安全的。
问, 你最多能抢劫到多少money。
思路:
抽象成背包问题, 每家银行只有两种选择, 要么抢, 要么不抢。
被抓的概率有点难求, 因为还要考虑之前没有被抓。这里换成求互斥事件:不被抓的概率。
概率为权值, money为重量, 状态转移方程:
dp[i] = max(dp[i], dp[i - money[j]] * (1 - p[j]))
最后在dp[money_count]里找到一个满足概率大于P 的最大下标即可。
代码:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <string>
#include <vector>
#include <fstream>
#include <iterator>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
#define MAXN 10010
#define MOD 1000000007
#define eps 1e-6
double dp[MAXN];
int w[MAXN];
double v[MAXN];
int n;
double p;
void show(int V)
{
for(int i = ; i <= V; i ++)
printf(dp[i] == INF? "INF ," : "%.3lf ,", dp[i]);
printf("\n");
}
void ZeroOnePack(int V, int n)
{
fill(dp, dp + V + , ); dp[] = 1.0;
for(int i = ; i < n; i ++)
for(int j = V; j >= w[i]; j --)
dp[j] = max(dp[j], dp[j - w[i]] * ( - v[i]));
} int main()
{
int T;
int kcase = ;
scanf("%d", &T);
while(T --)
{
int V = ;
scanf("%lf %d", &p, &n);
for(int i = ; i < n; i ++)
{
scanf("%d %lf", &w[i], &v[i]);
V += w[i];
}
ZeroOnePack(V, n);
int ans = ;
for(int i = ; i <= V; i ++)
if(dp[i] > ( - p))
ans = max(ans, i);
printf("Case %d: %d\n", ++ kcase, ans);
}
return ;
}
LightOj_1079 Just another Robbery的更多相关文章
- zoj 3511 Cake Robbery(线段树)
problemCode=3511" target="_blank" style="">题目链接:zoj 3511 Cake Robbery 题目 ...
- Just another Robbery(背包)
1079 - Just another Robbery PDF (English) Statistics Forum Time Limit: 4 second(s) Memory Limit: 3 ...
- UVA 707 - Robbery(内存搜索)
UVA 707 - Robbery 题目链接 题意:在一个w * h的图上.t个时刻,然后知道一些信息,每一个时刻没有小偷的矩阵位置,问哪些时刻能够唯一确定小偷位置.和确定小偷是否已经逃走,假设没逃走 ...
- (概率 01背包) Just another Robbery -- LightOJ -- 1079
http://lightoj.com/volume_showproblem.php?problem=1079 Just another Robbery As Harry Potter series i ...
- Codeforces Round #414 A. Bank Robbery
A. Bank Robbery time limit per test 2 seconds memory limit per test 256 megabytes A robber has a ...
- Robbery(记忆化搜索)
Robbery Inspector Robstop is very angry. Last night, a bank has been robbed and the robber has not b ...
- LightOJ - 1079 Just another Robbery —— 概率、背包
题目链接:https://vjudge.net/problem/LightOJ-1079 1079 - Just another Robbery PDF (English) Statistics ...
- poj-1104 Robbery
Robbery Time Limit: 1000MS Memory Limit: 32768K Total Submissions: 1249 Accepted: 504 Descriptio ...
- 1163 - Bank Robbery
1163 - Bank Robbery In one very cold morning, Mark decides to rob a bank. But while trying hacking ...
随机推荐
- Title Case
地址:http://www.codewars.com/kata/5202ef17a402dd033c000009/train/python 题目: A string is considered to ...
- JSP&Servlet学习手册
JSP&Servlet学习手册 沙琪玛 书 目录 JSP 指令... 3 书写方式... 3 指令列表... 3 JSP 内置对象... 3 内置对象特点... 3 常用内置对象... 3 o ...
- 经典SQL语句大全之基本函数
SQL Server基本函数 1.字符串函数 长度与分析用 1,datalength(Char_expr) 返回字符串包含字符数,但不包含后面的空格2,substring(expression,sta ...
- NodeJs读取源代码使用的字符集
今天用NodeJs写了个简单的客户端/服务器程序,并让客户端向服务器发送汉字.当在Windows上执行客户端时,发现服务器端打印的接收到的数据是乱码.后来发现Windows上的客户端文件的储存编码方案 ...
- hdu2044java
一只小蜜蜂... Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- java Reference(摘录)
Java中的Reference对象和GC是紧密联系在一起的,Reference的实现也是和GC相关的. 强引用 强引用是Java中使用最普遍的引用,我们经常使用的Object o = new Obje ...
- android开发之使用拼音搜索汉字
国庆回了趟家,昨天真不想走,离家近的感觉太好.唉,不扯这些,说说今天的正事吧. 上篇博客中介绍了自定义AutoCompleteTextView ,但是用到了一个很蹩脚的技术,就是我们事先把每个汉字的拼 ...
- linux中的帮助命令 分类: linux 学习笔记 ubuntu 2015-07-05 19:07 31人阅读 评论(0) 收藏
说实话,到目前为止我还是不太习惯使用linux自带的帮助文档,遇到问题都是去查我自己下载的chm格式的命令大全,不过这些帮助命令我们还是有必要了解的. 1.man [要查看的命令名称] 例如想要查看l ...
- Google Map API v2 步步为营(一) ----- 初见地图
官方文档:https://developers.google.com/maps/documentation/android/start?hl=zh-CN 先谷歌后百度.使用google的api基本上按 ...
- javascript常用插件
Math.uuid.js 功能:js 版生成uuid 地址:http://www.broofa.com/ jquery.waterfall.js 功能:瀑布布局图片 地址:https://github ...