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. Latent Dirichlet Allocation 文本分类主题模型

    文本提取特征常用的模型有:1.Bag-of-words:最原始的特征集,一个单词/分词就是一个特征.往往一个数据集就会有上万个特征:有一些简单的指标可以帮助筛选掉一些对分类没帮助的词语,例如去停词,计 ...

  2. [WIN32]Win7软件部署清单

    工具类 DreamWeaver8 网页 XAMPP 集成的服务器/数据库 EPP4 PHP IDE JDK7 Sublime Text 2 VMWare 虚拟机 Notepad++ FoxitRead ...

  3. 改int非空自增列为int可为空列

    ) --声明读取数据库所有数据表名称游标mycursor1 open mycursor1 --从游标里取出数据赋值到我们刚才声明的数据表名变量中 fetch next from mycursor1 i ...

  4. Ubuntu 16.04 标题栏实时显示上下行网速、CPU及内存使用率--indicator-sysmonitor

    ---------------------------------------------------------------------------- 原文地址:http://blog.csdn.N ...

  5. Volley获取网络图片使用总结

    参考资料 http://www.3fwork.com/b600/001956MYM002697/ //缓存 int cacheSize= 10 * 1024 * 1024; //声明一个新的Reque ...

  6. Locality Sensitive Hash 局部敏感哈希

    Locality Sensitive Hash是一种常见的用于处理高维向量的索引办法.与其它基于Tree的数据结构,诸如KD-Tree.SR-Tree相比,它较好地克服了Curse of Dimens ...

  7. Packets(模拟 POJ1017)

    Packets Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 47750 Accepted: 16182 Description ...

  8. 【web必知必会】——图解HTTP(上)

    本篇总结关于http的相关知识,主要内容参考如下导图: 主要讲解的内容有: 1 URL与URI的区别. 2 请求报文与相应报文的内容. 3 GET与POST的区别. 4 http的cookie.持久化 ...

  9. EF生成实体模板改良

    也许介绍的方法并不是完美的解决方法 web工程里添加这两项 里面会生成两个模板文件 上下文模板和实体类模板,现在主要对实体类模板进行改良 1.讲using 放在文件头 <#=codeString ...

  10. 学习从零开始写jQuery框架

    随着时代发展,javascript阵营里面出现了越来越多的优秀的框架,大大简化了我们的开发工作,在我们使用这些框架的时候是不是也应该饮水思源想想它们都是怎样构建起来的呢?如果你不满足于仅仅是使用一些现 ...