有一个强盗要去几个银行偷盗,他既想多投点钱,又想尽量不被抓到。已知各个银行

的金钱数和被抓的概率,以及强盗能容忍的最大被抓概率。求他最多能偷到多少钱?

解:以概率为价值 问价值在合理范围背包的最大容量

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; struct bag
{
int v;
double p;
}Bag[];
double dp[]; int main()
{
int T,N;
double p;
scanf("%d",&T);
while(T--)
{
scanf("%lf %d",&p,&N);
int sum = ;
for(int i = ; i < N; i++)
{
scanf("%d%lf",&Bag[i].v,&Bag[i].p);
sum += Bag[i].v;
}
memset(dp,,sizeof(dp));
dp[] = ;
for(int i = ; i < N; i++)
{
for(int j = sum; j >= Bag[i].v; j--)
{
dp[j] = max(dp[j],dp[j-Bag[i].v]*(-Bag[i].p));
}
} for(int i = sum; i >= ; i--)
{
if(dp[i] > -p)
{
printf("%d\n",i);
break;
}
}
}
return ;
}

hdu2955_Robberies 01背包的更多相关文章

  1. UVALive 4870 Roller Coaster --01背包

    题意:过山车有n个区域,一个人有两个值F,D,在每个区域有两种选择: 1.睁眼: F += f[i], D += d[i] 2.闭眼: F = F ,     D -= K 问在D小于等于一定限度的时 ...

  2. POJ1112 Team Them Up![二分图染色 补图 01背包]

    Team Them Up! Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7608   Accepted: 2041   S ...

  3. Codeforces 2016 ACM Amman Collegiate Programming Contest A. Coins(动态规划/01背包变形)

    传送门 Description Hasan and Bahosain want to buy a new video game, they want to share the expenses. Ha ...

  4. 51nod1085(01背包)

    题目链接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1085 题意: 中文题诶~ 思路: 01背包模板题. 用dp[ ...

  5. *HDU3339 最短路+01背包

    In Action Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  6. codeforces 742D Arpa's weak amphitheater and Mehrdad's valuable Hoses ——(01背包变形)

    题意:给你若干个集合,每个集合内的物品要么选任意一个,要么所有都选,求最后在背包能容纳的范围下最大的价值. 分析:对于每个并查集,从上到下滚动维护即可,其实就是一个01背包= =. 代码如下: #in ...

  7. POJ 3624 Charm Bracelet(01背包)

    Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 34532   Accepted: 15301 ...

  8. (01背包变形) Cow Exhibition (poj 2184)

    http://poj.org/problem?id=2184   Description "Fat and docile, big and dumb, they look so stupid ...

  9. hdu3339 In Action(Dijkstra+01背包)

    /* 题意:有 n 个站点(编号1...n),每一个站点都有一个能量值,为了不让这些能量值连接起来,要用 坦克占领这个站点!已知站点的 之间的距离,每个坦克从0点出发到某一个站点,1 unit dis ...

随机推荐

  1. Java中String类中常用的方法

    1.字符串与字符数组的转换 用toCharArray()方法将字符串变为字符数组 String str = "abcdef"; char c[] = str.tocharArray ...

  2. 查看磁盘IO负载 - 看哪些进程在读写磁盘

    原文:http://www.cnblogs.com/cloudstorage/archive/2012/11/11/2764623.html 今天晚上发现服务器io有点高,顺带看看哪些进程在读写磁盘. ...

  3. Spring 缓存注解解析过程

    Spring 缓存注解解析过程 通过 SpringCacheAnnotationParser 的 parseCacheAnnotations 方法解析指定方法或类上的缓存注解, @Cacheable ...

  4. springMVC+Spring+Mybatis+Redis

    SPRINGMVC+MYBATIS+SPRING+REDIS 只作参考,以防忘记使用! mybatis的配置文件: <?xml version="1.0" encoding= ...

  5. P站图片下载工具。

    下载 Pixiv 的图片比较麻烦,就做了这么个东西. 主要就是用 HttpWebRequest HttpWebResponse 下载了网页的 html 代码然后截取里面的内容.代码上传到了文件里. p ...

  6. 阿里云 centos 部署 Django 可能遇到的问题

    问题一:版本限制   File "/Users/icourt/Desktop/hf/venv/lib/python3.7/site-packages/django/db/backends/m ...

  7. java基础/数据加解密(Mooc)

    一.消息摘要算法 常用摘要算法: 以下 (HEX)内容:bc指Bouncy Castle  |  cc指:Apache commons Codec 1.消息摘要算法MD5及MD族(MD2,MD4) 消 ...

  8. ubuntu/如何启动、关闭和设置ubuntu防火墙

    由于LInux原始的防火墙工具iptables过于繁琐,所以ubuntu默认提供了一个基于iptable之上的防火墙工具ufw. ubuntu 9.10默认的便是UFW防火墙,它已经支持界面操作了.在 ...

  9. adb 连接 mumu 模拟器

    [win版]adb connect 127.0.0.1:7555adb shell [mac版] adb kill-server && adb server && ad ...

  10. Unique Word Abbreviation

    An abbreviation of a word follows the form <first letter><number><last letter>. Be ...