Robberies

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 15649    Accepted Submission(s): 5747

Problem Description
The aspiring Roy the Robber has seen a lot of American movies, and knows that the bad guys usually gets caught in the end, often because they become too greedy. He has decided to work in the lucrative business of bank robbery only for a short while, before retiring to a comfortable job at a university.


For a few months now, Roy has been assessing the security of various banks and the amount of cash they hold. He wants to make a calculated risk, and grab as much money as possible.

His mother, Ola, has decided upon a tolerable probability of getting caught. She feels that he is safe enough if the banks he robs together give a probability less than this.

 
Input
The first line of input gives T, the number of cases. For each scenario, the first line of input gives a floating point number P, the probability Roy needs to be below, and an integer N, the number of banks he has plans for. Then follow N lines, where line j gives an integer Mj and a floating point number Pj . 
Bank j contains Mj millions, and the probability of getting caught from robbing it is Pj .
 
Output
For each test case, output a line with the maximum number of millions he can expect to get while the probability of getting caught is less than the limit set.

Notes and Constraints
0 < T <= 100
0.0 <= P <= 1.0
0 < N <= 100
0 < Mj <= 100
0.0 <= Pj <= 1.0
A bank goes bankrupt if it is robbed, and you may assume that all probabilities are independent as the police have very low funds.

 
Sample Input
3
0.04 3
1 0.02
2 0.03
3 0.05
0.06 3
2 0.03
2 0.03
3 0.05
0.10 3
1 0.03
2 0.02
3 0.05
 
Sample Output
2
4
6
 
Source
 
题目意思:
一个人去抢劫n个银行,初始给一个概率p,每个银行有能抢劫的价值和被抓住的概率,当抢劫银行被抓住的总概率小于p的时候认为这个人是安全的,求在安全状态下能抢劫到最多得价值。
 
思路:
若以被抓概率为体积、价值为价值,概率是浮点数无法作为数组下标,不可取。
若以价值为体积、被抓概率为价值,而背包的定义是体积一定时获得最多得价值和使得被抓概率尽可能小相反,不可取。
若以价值为体积、不被抓概率为价值,使得不被抓概率尽可能高,可取。
 
代码:
 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
using namespace std; #define N 105 int max(int x,int y){return x>y?x:y;}
int min(int x,int y){return x<y?x:y;}
int abs(int x,int y){return x<?-x:x;} int n;
int v[N];
double val[N];
double dp[N*N];
int V; main()
{
int i, j, k;
int t;
cin>>t;
while(t--){
double vv;
scanf("%lf %d",&vv,&n);
V=;
for(i=;i<=n;i++) {
scanf("%d %lf",&v[i],&val[i]);
val[i]=1.0-val[i];
V+=v[i];
}
memset(dp,,sizeof(dp));
dp[]=;
for(i=;i<=n;i++){
for(j=V;j>=v[i];j--)
dp[j]=max(dp[j],dp[j-v[i]]*val[i]);
}
for(i=V;i>=;i--){
if(dp[i]>=-vv) break;
}
if(i<) printf("0\n");
else
printf("%d\n",i);
}
}

HDU 2955 01背包(思维)的更多相关文章

  1. hdu 2955 01背包

    http://acm.hdu.edu.cn/showproblem.php?pid=2955 如果认为:1-P是背包的容量,n是物品的个数,sum是所有物品的总价值,条件就是装入背包的物品的体积和不能 ...

  2. Robberies hdu 2955 01背包

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

  3. hdu 1203 01背包 I need a offer

    hdu 1203  01背包  I need a offer 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1203 题目大意:给你每个学校得到offe ...

  4. hdu 6092 Rikka with Subset(逆向01背包+思维)

    Rikka with Subset Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  5. hdu 6092 Rikka with Subset 01背包 思维

    dp[i][j]表示前i个元素,子集和为j的个数.d[i][j] = d[i][j] + d[i-1][j-k] (第i个元素的值为k).这里可以优化成一维数组 比如序列为 1 2 3,每一步的dp值 ...

  6. HDU 2955 Robberies 背包概率DP

    A - Robberies Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submi ...

  7. HDU 1171 Big Event in HDU【01背包/求两堆数分别求和以后的差最小】

    Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...

  8. poj3211Washing Clothes(字符串处理+01背包) hdu1171Big Event in HDU(01背包)

    题目链接: id=3211">poj3211  hdu1171 这个题目比1711难处理的是字符串怎样处理,所以我们要想办法,自然而然就要想到用结构体存储.所以最后将全部的衣服分组,然 ...

  9. hdu 1864 01背包 最大报销额

    http://acm.hdu.edu.cn/showproblem.php?pid=1864 New~ 欢迎“热爱编程”的高考少年——报考杭州电子科技大学计算机学院关于2015年杭电ACM暑期集训队的 ...

随机推荐

  1. 关于jquery-validate验证表单

    最近在做微信端的界面,一直写表单验证!一直在写表单验证!发现jquery-validate还真是好用哎,今天总结了一些: (1)required:true 必输字段(2)remote:"ch ...

  2. Android安装失败 Installation error code: -110

    在系统开发过程中,开发的app管理器,发现怎么安装都是失败. 详细的查看了log发现. I/ActivityManager(  899): START {dat=file:///mnt/sdcard/ ...

  3. Android中AIDL通信机制分析

    一.背景 ·1.AIDL出现的原因 在android系统中,每一个程序都是运行在自己的进程中,进程之间无法进行通讯,为了在Android平台,一个进程通常不能访问另一个进程的内存空间,所以要想对话,需 ...

  4. linux查看磁盘系统df,du

    可以用df命令轻松地查看所有已挂载磁盘的使用情况 df df -h 把输出的文件单位换成文件可读的单位 du 命令显示特定目录的使用情况 du -c 显示总用量 du -h 人类可读性 du -s 每 ...

  5. Java虚拟机学习(1):体系结构 内存模型

    一:Java技术体系模块图 Java技术体系模块图 二:JVM内存区域模型 1.方法区 也称"永久代" ."非堆",  它用于存储虚拟机加载的类信息.常量.静态 ...

  6. 模块(序列化(json&pickle)+XML+requests)

    一.序列化模块 Python中用于序列化的两个模块: json     跨平台跨语言的数据传输格式,用于[字符串]和 [python基本数据类型] 间进行转换 pickle   python内置的数据 ...

  7. 【转】malloc与free的底层实现

    本文转自:http://blog.163.com/xychenbaihu@yeah/blog/static/132229655201210975312473/ 如何查看进程发生缺页中断的次数? 用ps ...

  8. pickle与shelve

    pickle Example 写入文件 import pickle integers = [1, 2, 3, 4, 5] with open('pickle-example.p', 'wb') as ...

  9. IntelliJ IDEA使用(2)——IDEA配置Tomcat

    如果网上流传的方法(即方法2)不能配置成功,点击加号什么都没有的话,请看方法一配置方法. 解决问题:intlellij IDEA配置tomcat点击加号没东西. 方法一:手动添加tomcat插件然后再 ...

  10. 系统巡警 v1.2 系统行为分析神器

    系统巡警,是一款安全辅助软件,可以帮助系统维护人员或安全研究人员观察系统运行情况,包括进程启动与销毁记录.模块加载记录.线程启动与销毁记录.系统服务创建修改和删除记录.文件与文件夹的增加删除和修改记录 ...