HDU 2955 01背包(思维)
Robberies
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 15649 Accepted Submission(s): 5747

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.
Bank j contains Mj millions, and the probability of getting caught from robbing it is Pj .
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.
一个人去抢劫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背包(思维)的更多相关文章
- hdu 2955 01背包
http://acm.hdu.edu.cn/showproblem.php?pid=2955 如果认为:1-P是背包的容量,n是物品的个数,sum是所有物品的总价值,条件就是装入背包的物品的体积和不能 ...
- Robberies hdu 2955 01背包
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- hdu 1203 01背包 I need a offer
hdu 1203 01背包 I need a offer 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1203 题目大意:给你每个学校得到offe ...
- hdu 6092 Rikka with Subset(逆向01背包+思维)
Rikka with Subset Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- 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值 ...
- HDU 2955 Robberies 背包概率DP
A - Robberies Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- 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 ...
- poj3211Washing Clothes(字符串处理+01背包) hdu1171Big Event in HDU(01背包)
题目链接: id=3211">poj3211 hdu1171 这个题目比1711难处理的是字符串怎样处理,所以我们要想办法,自然而然就要想到用结构体存储.所以最后将全部的衣服分组,然 ...
- hdu 1864 01背包 最大报销额
http://acm.hdu.edu.cn/showproblem.php?pid=1864 New~ 欢迎“热爱编程”的高考少年——报考杭州电子科技大学计算机学院关于2015年杭电ACM暑期集训队的 ...
随机推荐
- asp检测数字类型函数
'**************************************************'函数ID:0014[检测ID是否为数字类型]'函数名:JCID'作 用:检测ID是否为数字类型' ...
- 【转】PowerShell入门(七):管道——在命令行上编程
转至:http://www.cnblogs.com/ceachy/archive/2013/02/22/PowerShell_Pipeline.html 管道对于Shell来说是个化腐朽为神奇的东西, ...
- c#下载网页源码的两种方法
1.WebClient: System.Net.WebClient wc = new System.Net.WebClient(); Byte[] pageData = wc.DownloadData ...
- 【转】mysql安装图解
转载地址:http://www.jb51.net/article/23876.htm 很多朋友刚开始接触mysql数据库服务器,下面是网友整理的一篇mysql的安装教程,步骤明细也有详细的说明. ...
- a标签样式
.a{ cursor:pointer; color: blue; text-decoration:none; }
- 20160330001 调用及触发Office Outlook 约会
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...
- 【leetcode❤python】 203. Remove Linked List Elements
#-*- coding: UTF-8 -*- # Definition for singly-linked list.# class ListNode(object):# def __init ...
- CentOS 7数据库mysql和mariadb手动安装冲突的问题解决
由于确定使用mysql,那只有卸载mariadb了. 一.首先查看当前安装的mariadb包 rpm -qa|grep mariadb 本人得到结果是:mariadb-libs-5.5.44-2.el ...
- aws在线技术峰会笔记-游戏解决方案
选项1:可以将aws的SDK嵌入到APP中. 选项2:Mobile Hub自动生成代码. 选项3:开源免费的游戏引擎.可视化脚本编程,实现客户端的逻辑代码. 用户管理 Cognito Identity ...
- ie7 父元素宽度自适应且为浮动的话 子元素的宽度将不能按比例设置问题
好久没切图,昨天遇到个浏览器兼容的老问题,在ie7下,父元素设置浮动后,其宽度是自适应的,子元素的宽度若没有确定则将显示最小宽度,即文本所占的宽度. 正常其他浏览器显示如下: ie7中显示效果如下: ...