01背包+卡精度 Hdu 2955
<span style="color:#3333ff;">/*
—————————————————————————————————————————————————————————————————————————————
author : Grant Yuan
time : 2014.7.19
aldorithm: 01背包+卡精度 —————————————————————————————————————————————————————————————————————————————
E - 01背包 基础
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit Status
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<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std; int p[105];
double f[105];
int n,t;
double ff;
double dp[100005];//抢到价值为i的钱逃走的最大概率
int sum; int main()
{
cin>>t;
while(t--){
sum=0;
scanf("%lf%d",&ff,&n);
for(int i=0;i<n;i++){
scanf("%d%lf",&p[i],&f[i]);
sum+=p[i];} memset(dp,0,sizeof(dp));
dp[0]=1;
for(int i=0;i<n;i++)
for(int j=sum;j>=p[i];j--)
{
dp[j]=max(dp[j],dp[j-p[i]]*(1-f[i]));
}
int m=0;
for(int i=sum;i>=0;i--)
{
if(dp[i]>=1-ff){
m=i;
break;}
}
cout<<m<<endl;
}
}
</span>
01背包+卡精度 Hdu 2955的更多相关文章
- hdu 01背包汇总(1171+2546+1864+2955。。。
1171 题意比较简单,这道题比较特别的地方是01背包中,每个物体有一个价值有一个重量,比较价值最大,重量受限,这道题是价值受限情况下最大,也就值把01背包中的重量也改成价值. //Problem : ...
- hdu 2955 01背包
http://acm.hdu.edu.cn/showproblem.php?pid=2955 如果认为:1-P是背包的容量,n是物品的个数,sum是所有物品的总价值,条件就是装入背包的物品的体积和不能 ...
- HDU 2546 饭卡(01背包裸题)
饭卡 Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...
- hdu 2955 Robberies (01背包)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 思路:一开始看急了,以为概率是直接相加的,wa了无数发,这道题目给的是被抓的概率,我们应该先求出总的 ...
- HDOJ(HDU).2546 饭卡(DP 01背包)
HDOJ(HDU).2546 饭卡(DP 01背包) 题意分析 首先要对钱数小于5的时候特别处理,直接输出0.若钱数大于5,所有菜按价格排序,背包容量为钱数-5,对除去价格最贵的所有菜做01背包.因为 ...
- HDU 2546 饭卡(01 背包)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=2546 思路:需要首先处理一下的的01背包,当饭卡余额大于等于5时,是什么都能买的,所以题目要饭卡余额最小, ...
- 【01背包变形】Robberies HDU 2955
http://acm.hdu.edu.cn/showproblem.php?pid=2955 [题意] 有一个强盗要去几个银行偷盗,他既想多抢点钱,又想尽量不被抓到.已知各个银行 的金钱数和被抓的概率 ...
- hdu 2546 饭卡 (01背包)
Problem Description 电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负) ...
- HDU 2546:饭卡(01背包)
饭卡 Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...
随机推荐
- php官方微信接口大全
微信入口绑定,微信事件处理,微信API全部操作包含在这些文件中.内容有:微信摇一摇接口/微信多客服接口/微信支付接口/微信红包接口/微信卡券接口/微信小店接口/JSAPI <?php class ...
- 【转载】CentOS7 安装Chrome浏览器
本篇文章主要记录如何在CentOS7.0上安装Chrome浏览器. 方法1: Google官方源在国内可能无法正常访问,故而添加Fedora中文社区提供的镜像源: sudo wget http://r ...
- 逻辑回归(Logistic Regression)算法小结
一.逻辑回归简述: 回顾线性回归算法,对于给定的一些n维特征(x1,x2,x3,......xn),我们想通过对这些特征进行加权求和汇总的方法来描绘出事物的最终运算结果.从而衍生出我们线性回归的计算公 ...
- Linux下dpkg的用法
转自:http://blog.csdn.net/fireblue1990/article/details/52627952 dpkg是一个Debian的一个命令行工具,它可以用来安装.删除.构建和管理 ...
- iOS学习笔记21-推送证书与秘钥申请
---恢复内容开始--- 一.iOS证书 iOS常用的证书包括开发证书和发布证书,无论是真机调试还是最终发布应用到App Store这两个证书都是必须的,它是iOS开发的基本证书.Xcode7以后真机 ...
- [luoguP2331] [SCOI2005]最大子矩阵(DP)
传送门 orz不会做... 一个好理解的做法(n^3*k): 分n=1和n=2两种情况考虑. n=1时,预处理出前缀和sum[]. 设f[i][j]为到达第i格,已经放了j个子矩阵的最大和, 那么每次 ...
- 【gets getline的用法 char[]转化为str】poj 2418
http://poj.org/problem?id=2418 [注意] 1. 输入有空格,用 char str[maxn]; while(gets(str)){ str[]!='\0'; } 或 st ...
- Spring JdbcTemplate操作小结
Spring 提供了JdbcTemplate 来封装数据库jdbc操作细节: 包括: 数据库连接[打开/关闭] ,异常转义 ,SQL执行 ,查询结果的转换 使用模板方式封装 jdbc数据库操作-固定流 ...
- vs2015插件推荐 Productivity Power Tools 2015
vs2015插件推荐 Productivity Power Tools 2015 官网网址:https://marketplace.visualstudio.com/items?itemName=Vi ...
- nosql整理
Nosql: Redis,Memcache,MongoDB,Hbase,Couchbase LevelDB https://www.cnblogs.com/lina520/p/7919551.htm ...