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 ...
随机推荐
- Can't connect to MySQL server on localhost (10061)解决方法
出现这种错误的原因是由于MySQL的服务被关闭的原因,重新启动一下服务就可以了,启动服务的操作如下: 右键[计算机]-[管理]
- java数组的拷贝四种方法:for、clone、System.arraycopy、arrays.copyof
public class ArrayCopy{ public static void main(String []args){ int []a = {1,3,4,5}; toPrint(a); int ...
- Java IO流学习总结(转)
Java流操作有关的类或接口: Java流类图结构: 流的概念和作用 流是一组有顺序的,有起点和终点的字节集合,是对数据传输的总称或抽象.即数据在两设备间的传输称为流,流的本质是数据传输,根据数据传输 ...
- Linux模式设计系列( 内核与应用关联思考)
http://blog.chinaunix.net/uid/20608849/cid-25333-list-2.html
- Mac上pod install一直停住的解决办法
pod install一直停住的解决办法 在/Users/XXX/.cocoapods/repos下 git clone https://github.com/CocoaPods/Specs.git ...
- Silverlight OOB 程序自动更新
Silverlight OOB 程序 提供了非常方便的自动更新功能! 要让 Silverlight OOB 安装到客户端电脑后实现自动更新,必须实现以下两个条件: 一.为 程序的 xap 文件进行签 ...
- Android本地JUnit Text
Android本地JUnit Text 步骤 创建一个和source文件,里面添加和src目录相同的包. 在AndroidManifest.xml文件manifest根节点添加如下文件 <ins ...
- Oracle 日期类型timestamp(时间戳)和date类型使用
body { font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI ...
- 批量翻转PNG图片
用了好几个软件都不好用. 要么不能翻转PNG, 要么翻转之后没有透明度了. 基本上全是图形界面, 要鼠标批量拖放. 所以, 还是自己动手, 写一个批量png翻转工具. #include <ios ...
- Hadoop学习第一天
1.hadoop量大,数目多. 存储:分布式,集群的概念,管理(主节点.从节点),HDFS. 分析:分布式.并行.离线计算框架,管理(主节点.从节点),MapReduce. 来源:GFS->HD ...