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 ...
随机推荐
- [D3] 6. Color Scale
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- android 73 下载图片
package com.ithiema.imageviewer; import java.io.InputStream; import java.net.HttpURLConnection; impo ...
- bash if 表达式
.bash把[[ $a -lt $b ]]看作一个单独的元素,并且返回一个退出码.退出码0为真,非零为假 例如: a= b=c [[ $a -lt $b ]] echo $? # a小于b为真 [[ ...
- CentOS6.4下使用默认的文档查看器打开PDF文档乱码的解决方案
最近在CentOS6.4下使用其默认的文档查看器打开PDF文档时出现乱码的方块,有两种方法可以解决. 方法一:修改/etc/fonts/conf.d/49-sansserif.conf文件,如 ...
- Oracle11g新特性导致空表不能导出问题
ORACLE 11G在用EXP导出时,发现空表(没有数据或者没有用过的表)不能导出了. 查了一下资料,说是Oracle 11G中有个新特性,当表无数据时,不分配segment,以节省空 ...
- .NET生成PDF文件
C#未借助第三方组件,自己封装通用类,生成PDF文件. 调用方式: //路径 string path = @"C:\yuannwu22.pdf"; //内容 string strC ...
- PHP关闭Notice错误提示
原文出处 本文章介绍在php中关闭notice错误的一些做法,但是不得不说的是在关掉错误提示时,那么程序代码中大量的notice级别错误是否会造成PHP性能下降 PHP Notice: Undefin ...
- Linux - 扩展
每次输入命令行按下 Enter 键时,bash 都会在执行命令之前对文本进行多重处理.比如 "cd ~" 中的 "~" 的会被识别为当前用户的主目录.产生这个结 ...
- orm fluentdata使用相关文章
微型orm fluentdata使用:http://www.360doc.com/content/12/1228/23/9200790_256885743.shtml
- ios专题 - 斯坦福大学iOS开发公开课总结
转自:http://blog.devtang.com/blog/2012/02/05/mvc-in-ios-develop/ 前言 iphone开发相关的教程中最有名的,当数斯坦福大学发布的”ipho ...