<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的更多相关文章

  1. hdu 01背包汇总(1171+2546+1864+2955。。。

    1171 题意比较简单,这道题比较特别的地方是01背包中,每个物体有一个价值有一个重量,比较价值最大,重量受限,这道题是价值受限情况下最大,也就值把01背包中的重量也改成价值. //Problem : ...

  2. hdu 2955 01背包

    http://acm.hdu.edu.cn/showproblem.php?pid=2955 如果认为:1-P是背包的容量,n是物品的个数,sum是所有物品的总价值,条件就是装入背包的物品的体积和不能 ...

  3. HDU 2546 饭卡(01背包裸题)

    饭卡 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...

  4. hdu 2955 Robberies (01背包)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 思路:一开始看急了,以为概率是直接相加的,wa了无数发,这道题目给的是被抓的概率,我们应该先求出总的 ...

  5. HDOJ(HDU).2546 饭卡(DP 01背包)

    HDOJ(HDU).2546 饭卡(DP 01背包) 题意分析 首先要对钱数小于5的时候特别处理,直接输出0.若钱数大于5,所有菜按价格排序,背包容量为钱数-5,对除去价格最贵的所有菜做01背包.因为 ...

  6. HDU 2546 饭卡(01 背包)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=2546 思路:需要首先处理一下的的01背包,当饭卡余额大于等于5时,是什么都能买的,所以题目要饭卡余额最小, ...

  7. 【01背包变形】Robberies HDU 2955

    http://acm.hdu.edu.cn/showproblem.php?pid=2955 [题意] 有一个强盗要去几个银行偷盗,他既想多抢点钱,又想尽量不被抓到.已知各个银行 的金钱数和被抓的概率 ...

  8. hdu 2546 饭卡 (01背包)

    Problem Description 电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负) ...

  9. HDU 2546:饭卡(01背包)

    饭卡 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...

随机推荐

  1. 【04】图解JSON

    [04]图解JSON   附件列表

  2. angularJs模块ui-router之多视图

    可以给ui-view指定名称,这样一个模板中就可以有多个ui-view.假设您有一个应用,需要动态填充graph.table data和filters,像下面这样: 当您需要使用多视图时,需要用到状态 ...

  3. Python内置函数(4)

    Python内置函数(4) 1.copyright 交互式提示对象打印许可文本,一个列表贡献者和版权声明 2.credits 交互式提示对象打印许可文本,一个贡献者和版权声明的列表 3.delattr ...

  4. pytion3--用户定义的迭代器

    1.迭代器基于下面两个个方法: (1)__next__ 返回容器的下一个项目(2)__iter__ 返回迭代器本身 2.当序列遍历完时,将抛出StopIteration异常,所以通过捕获这个异常来停止 ...

  5. Leetcode 373.查找和最小的k对数字

    查找和最小的k对数字 给定两个以升序排列的整形数组 nums1 和 nums2, 以及一个整数 k. 定义一对值 (u,v),其中第一个元素来自 nums1,第二个元素来自 nums2. 找到和最小的 ...

  6. 雅礼培训4.3 Problem A 【点分治】

    题目简述 一个\(N\)个节点的树,有\(M\)个炸弹分布在一些节点上,有各自的威力,随着其他点距离增大对其他点的伤害呈等差减小,直至为0 问每个点受到的伤害 题解 QAQ考场代码没处理好有些炸弹威力 ...

  7. BZOJ2561 最小生成树 【最小割】

    题目 给定一个边带正权的连通无向图G=(V,E),其中N=|V|,M=|E|,N个点从1到N依次编号,给定三个正整数u,v,和L (u≠v),假设现在加入一条边权为L的边(u,v),那么需要删掉最少多 ...

  8. mvc框架简介

    1.mvc( mode  view controller)是什么?   m指业务代码,v指用户界面,c是控制器 使用MVC的目的是将M和V的实现代码分离,从而使同一个程序可以使用不同的表现形式 是一种 ...

  9. 类 this指针 const成员函数 std::string isbn() const {return bookNo;}

    转载:http://www.cnblogs.com/little-sjq/p/9fed5450f45316cf35f4b1c17f2f6361.html C++ Primer 第07章 类 7.1.2 ...

  10. mysql语句优化方案(网上流传)

    关于mysql处理百万级以上的数据时如何提高其查询速度的方法 最近一段时间由于工作需要,开始关注针对Mysql数据库的select查询语句的相关优化方法. 由于在参与的实际项目中发现当mysql表的数 ...