Robberies(简单的01背包 HDU2955)
Robberies 
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) 
Total Submission(s): 16565    Accepted Submission(s): 6087
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
#include <iostream>
#include <set>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
const int MAX=101000;
typedef pair<int ,double >pr;
typedef long long LL;
double Dp[11000];
pr a[110];
double s;
int n,sum;
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%lf %d",&s,&n);
        sum=0;
        for(int i=0;i<n;i++)
        {
            scanf("%d %lf",&a[i].first,&a[i].second);
            sum+=a[i].first;
        }
        memset(Dp,0,sizeof(Dp));
        Dp[0]=1;
        for(int i=0;i<n;i++)//将金钱作为重量概率作为价格进行01背包
        {
            for(int j=sum;j>=a[i].first;j--)
            {
                Dp[j]=max(Dp[j],Dp[j-a[i].first]*(1-a[i].second));
            }
        }
        int ans=0;
        s=1-s;
        for(int i=sum;i>0;i--)//要求是被抓住的概率小于s,就是不被抓住的概率大于(1-s)
        {
            if(s<Dp[i])
            {
                ans=i;
                break;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}
Robberies(简单的01背包 HDU2955)的更多相关文章
- HDU 2602 (简单的01背包) Bone Collector
		很标准的01背包问题 //#define LOCAL #include <algorithm> #include <cstdio> #include <cstring&g ... 
- Robberies   hdu 2955   01背包
		Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ... 
- HDU 2955 Robberies抢劫案(01背包,变形)
		题意:要抢劫,但是抢每个银行都有被抓的概率,问在低于规定的被抓概率情况下最多能抢到多少钱. 输入:第一行为T,表示共T个测试例子.每个例子的第一行给出一个浮点数P,是规定被抓的概率上限.第一行还有一个 ... 
- 【hdu2955】 Robberies 01背包
		标签:01背包 hdu2955 http://acm.hdu.edu.cn/showproblem.php?pid=2955 题意:盗贼抢银行,给出n个银行,每个银行有一定的资金和抢劫后被抓的概率,在 ... 
- POJ 3624 Charm Bracelet 简单01背包
		题目大意:有n件珠宝,每个珠宝的魅力值为v,重量为w,求在重量不超过m的情况下能达到的最大魅力值. 题目思路:简单的01背包,由于二维数组会超内存所以应该压缩成一维数组. dp[i][j],表示选取i ... 
- UVALive 4870 Roller Coaster  --01背包
		题意:过山车有n个区域,一个人有两个值F,D,在每个区域有两种选择: 1.睁眼: F += f[i], D += d[i] 2.闭眼: F = F , D -= K 问在D小于等于一定限度的时 ... 
- 【HDU 3810】 Magina (01背包,优先队列优化,并查集)
		Magina Problem Description Magina, also known as Anti-Mage, is a very cool hero in DotA (Defense of ... 
- HDU 1203 I NEED A OFFER! 01背包
		题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1203 解题思路:简单的01背包,用dp[i]表示花费不超过i时的最大可能性 状态转移方程 dp[i]= ... 
- HDU -1864最大报销额(01背包)
		这道题属于简单的01背包,但是背包问题还算简单,就是前面的细节处理的时候要注意,题意大致说了三条限制吧 1. 只有a, b, c 三种类型的发票可以报销,其它的一律不报销 2. 物品单项的报销额不超过 ... 
随机推荐
- .NET业务实体类验证组件Fluent Validation
			认识Fluent Vaidation. 看到NopCommerce项目中用到这个组建是如此的简单,将数据验证从业务实体类中分离出来,真是一个天才的想法,后来才知道这个东西是一个开源的轻量级验证组建. ... 
- Mac 下 FlashBuilder的快捷键
			Option + 上/下 当前行上下调整位置 Shift + Command + 左/右 选择当前行 Option + Command + 左/右 查看上一个类 
- C++ set容器简单用法
			set是关联容器,类似于集合,里面的元素不会重复,而且呈现为有序性 常用操作: using namespace std; set<int>:s;1.元素插入:s.insert()2.中序遍 ... 
- C++之路进阶——codevs2404(糖果)
			2404 糖果 2011年省队选拔赛四川 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 大师 Master 题目描述 Description 幼儿园里有N个小朋友,l ... 
- C#写好的类库dll怎么在别人调用的时候也能看到注释?
			菜单 Project -> 'xxxx' Properties -> Build -> Output -> 勾上 XML Documentation file 
- react绑定事件
			1.显示隐藏 2.输入框输入内容,立即显示出来 代码如下: 注意:版本 React v15.0.1 ReactDOM v15.0.1 browser.min.js是编译文件,将代码解析为浏览器识别的j ... 
- 夺命雷公狗---node.js---16之项目的构建在node+express+mongo的博客项目1
			废话不多说我们直接开工... 直接在目录下打开黑窗口: 然后就开始看看我们创建出来的文件了: 然后就开始创建项目下的目录了: 从这里就可以清晰的看得到我们的目录都是以前后台来分离开来的,引入模版也很简 ... 
- 夺命雷公狗mongodb之----mongodb---1---的下载,安装,连接
			首先登录mongodb的官方网站即可进行下载: https://www.mongodb.com/download-center?jmp=nav#community 然后到wamp目录下创建一个mong ... 
- [Ubuntu] Remove Byte Order Mark (BOM) from files recursively [Forward article]
			Original article: http://www.yiiframework.com/wiki/570/remove-byte-order-mark-bom-from-files-recursi ... 
- 为什么DIY报价----走出软件作坊:三五个人十来条枪 如何成为开发正规军(十二)[转]
			前段时间,写了一个开发.实施.服务费用计算三部曲. 水清则无鱼--走出软件作坊:三五个人十来条枪 如何成为开发正规军(八) 实施费用也能DIY--走出软件作坊:三五个人十来条枪 如何成为开发正规军(九 ... 
