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. 手机APP测试体系

  2. jquery判断id是否存在

    1.判断标签是否存在 ){ 存在 } 2.判断(id="id名"的标签)是否存在,下面的不可以!!!因为 $("#id") 不管对象是否存在都会返回 objec ...

  3. 使用HttpClient发送数据 到WebApi

    发送和JSON数据 /=============================webAPI接受POST的JOSN数据=============================/ POST api/& ...

  4. winform在不同电脑分辨率

    private void InitializeComponent() { //设定按字体来缩放控件 this.AutoScaleMode = System.Windows.Forms.AutoScal ...

  5. Web Performance Test: 如果使用Plugin过滤Dependent Request

    前言 由于Visual Studio的Web Performance Test是基于XML脚本的,留给用户修改测试行为的自由度并不高.因此,Plugin机制就对于实现很多客户化的配置显得很重要. 问题 ...

  6. 【iOS】Foundation框架 学习笔记

    1.数组 OC数组不能存放nil值OC数组只能存放OC对象.不能存放非OC对象类型,比如int.struct.enum等 ====================================== ...

  7. 第 十一 天 Flagmeng 和动画

    1.flagment 的使用,生命周期. 传递数据. 2. 基本动画的使用. 3. 对话框的使用. 4.样式和主题.

  8. Maven学习(二) -- 坐标和依赖

    标签(空格分隔): 学习笔记 坐标 实际就像在几何中,我们用一对坐标(x, y)来表示坐标系中唯一的点:或者我们可以用(经度,纬度)来表示地球上的某一个位置,在Maven的世界中,有坐标来唯一的表示项 ...

  9. <a>每次点击都会让浏览器重新打开一个窗口问题

    <a> 标签的 target 属性规定在何处打开链接文档.如果在一个 <a> 标签内包含一个 target 属性,浏览器将会载入和显示用这个标签的 href 属性命名的.名称与 ...

  10. 《K&R》里贯穿全书的代码

    个人阅读<K&R>的感觉就是:前后内容联系特别紧密,前面的代码没有理解好到了后面就看不下去. 1.getline(char s[], int lim) 调用结果:往参数数组中读入字 ...