题目链接

题意:

  抢银行(这个背景最爱了), 有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. C#中npoi操作Excel[版本2.0.1读写2003、2007格式]

    下载npoi2.0.1dll文件:http://download.csdn.net/detail/pukuimin1226/5851747 public static void test1()     ...

  2. MVC 音乐商店 第 9 部分: 注册和结帐

    MVC 音乐商店是介绍,并分步说明了如何使用 ASP.NET MVC 和 Visual Studio 为 web 开发教程应用程序. MVC 音乐商店是一个轻量级的示例存储实现它卖音乐专辑在线,并实现 ...

  3. 让Tomcat支持中文路径名和中文文件名

    http://hdwangyi.iteye.com/blog/107709 Tomcat是Java开发者使用得较多的一个Web服务器,因为它占用资源小,运行速度快等特点,深受Java Web程序员的喜 ...

  4. [Webpack 2] Tree shaking with Webpack 2

    The less code you can send to the browser, the better. The concept of tree shaking basically says th ...

  5. SVN安装手册

    转:http://www.cnblogs.com/newsea/archive/2012/04/28/2474818.html 常用工具2012-04-04 21:24        by       ...

  6. ajax大数据排队导出+进度条

    描述 :我们现在有很多数据,分表存放,现在需要有精度条的导出.最后面有完整源码. 效果图:

  7. android 6.0获取 WRITE_SETTINGS 权限

    android 6.0上只写在AndroidManifest中是不行的,还必须手动打开才行 private void setBrightnessMode(Context context, int mo ...

  8. winform鼠标滚轮事件

    #region 进入窗体时加载 public FormAlarmInfoQuery() { InitializeComponent(); pictureBox1.ImageLocation = &qu ...

  9. 每日陌生php函数

    1,date_default_timezone_set(PRC) 设定一个脚本中所有日期函数的默认时区,PRC设置中国时区 2,microtime(true) 返回当前unix微秒时间戳 139868 ...

  10. Video事件、方法-- DOM

    <video> 元素同样拥有方法.属性和事件.其中的方法用于播放.暂停以及加载等.其中的属性(比如时长.音量等)可以被读取或设置.其中的 DOM 事件能够通知您,比方说,<video ...