题目链接

题意:

  抢银行(这个背景最爱了), 有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的更多相关文章

  1. zoj 3511 Cake Robbery(线段树)

    problemCode=3511" target="_blank" style="">题目链接:zoj 3511 Cake Robbery 题目 ...

  2. Just another Robbery(背包)

    1079 - Just another Robbery   PDF (English) Statistics Forum Time Limit: 4 second(s) Memory Limit: 3 ...

  3. UVA 707 - Robbery(内存搜索)

    UVA 707 - Robbery 题目链接 题意:在一个w * h的图上.t个时刻,然后知道一些信息,每一个时刻没有小偷的矩阵位置,问哪些时刻能够唯一确定小偷位置.和确定小偷是否已经逃走,假设没逃走 ...

  4. (概率 01背包) Just another Robbery -- LightOJ -- 1079

    http://lightoj.com/volume_showproblem.php?problem=1079 Just another Robbery As Harry Potter series i ...

  5. 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 ...

  6. Robbery(记忆化搜索)

    Robbery Inspector Robstop is very angry. Last night, a bank has been robbed and the robber has not b ...

  7. LightOJ - 1079 Just another Robbery —— 概率、背包

    题目链接:https://vjudge.net/problem/LightOJ-1079 1079 - Just another Robbery    PDF (English) Statistics ...

  8. poj-1104 Robbery

    Robbery Time Limit: 1000MS   Memory Limit: 32768K Total Submissions: 1249   Accepted: 504 Descriptio ...

  9. 1163 - Bank Robbery

    1163 - Bank Robbery   In one very cold morning, Mark decides to rob a bank. But while trying hacking ...

随机推荐

  1. 如何利用 _ViewStart.cshtml对页面添加代码?

    _ViewStart.cshtml 添加的代码会出现在页面的最上面(<html> 之前) .这样就造成了我原先很多页面出现兼容性问题(经难是因为<html>之前出现了其它的代码 ...

  2. Oracle怎么更改用户名

    http://blog.csdn.net/weiwenhp/article/details/8094575 目录(?)[-] 改用户名的用处 怎么改用户名 还要做的工作 想干坏事明文显示密码   很多 ...

  3. IIS Shared Configuration

    Introduction The Internet changes the ways in which companies handle their day-to-day business and h ...

  4. Google C++ Style Guide在C++11普及后的变化

    转 http://www.cnblogs.com/chen3feng/p/5972967.html?from=timeline&isappinstalled=0&lwfrom=user ...

  5. python matplotlib.plot画图显示中文乱码的问题

    在matplotlib.plot生成的统计图表中,中文总是无法正常显示.在网上也找了些资料,说是在程序中指定字体文件,不过那样的话需要对plot进行很多设置,而且都是说的设置坐标轴标题为中文,有时候图 ...

  6. Asp.net Mvc对比Php的4大误解

    一:asp.net技术已过时,Php技术更新 Asp.net mvc 5 发布于2014 夏天. 二:php开发者更多,所以更能得到帮助 2者对比犹如下图,会拿电锯的肯定多少会点锯子, 会用锯子的不一 ...

  7. SQL多表查询中的分页,字段组合综合实例解析

    原文:http://www.jb51.net/article/28753.htm http://xuzhihong1987.blog.163.com/blog/static/2673158720098 ...

  8. [DEncrypt] Encrypt--加密/解密/MD5加密 (转载)

    点击下载  Encrypt.zip 这个类是关于加密,解密的操作,文件的一些高级操作1.Encrypt加密2.Encrypt解密3.Encrypt MD5加密看下面代码吧 /// <summar ...

  9. .NET设计模式(9):桥接模式(Bridge Pattern)

      .NET设计模式(9):桥接模式(Bridge Pattern)   桥接模式(Bridge Pattern) --.NET设计模式系列之九 年月 实现代码如下:..所谓抽象和实现沿着各自维度的变 ...

  10. javascript - 清空一个 array

    我觉得javascript不容易, 许多人觉得js容易, 因为他们觉得很容易写出常用的需求, 但是当我们实际做项目的时候, 对于javascript的要求是很高的, 特别是在性能需求方面. 我写这句话 ...