<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. luogu1879 [USACO06NOV]玉米田Corn Fields

    学习位运算 #include <iostream> #include <cstdio> using namespace std; int n, m, dp[15][4105], ...

  2. android 之 TabHost

    TabHost的实现有两种方式,第一种继承TabActivity,从TabActivity中用getTabHost()方法获取TabHost.各个Tab中的内容在布局文件中定义就行了. mainAct ...

  3. 分离焦虑OR责任焦虑

     这里是用小孩上幼儿园的事说分离焦虑,转念到成人身上就是责任焦虑.        这周小孩开始上幼儿园了,他很害怕家长离开,我能做的也不多,只是很肯定的告诉他,爸爸就在停车场,下学就来接你,然后从各个 ...

  4. Linux rm删除

    将 test1子目录及子目录中所有档案删除 命令: rm -r test1 rm -rf test2命令会将 test2 子目录及子目录中所有档案删除,并且不用一一确认 命令: rm -rf  tes ...

  5. 【总集】C++ STL类库 vector 使用方法

    介绍: 1.vector 的中文名为向量,可以理解为一个序列容器,里面存放的是相同的数据结构类型,类似于数组但与数组又有微妙的不同. 2.vector 采用的是连续动态的空间来存储数据,它是动态的数组 ...

  6. 【Luogu】P2617Dynamic Ranking(树状数组套主席树)

    题目链接 树状数组套主席树有点难懂qwq 不好理解 树状数组套主席树的直观理解应该是:树状数组的每一个节点是一棵主席树. 普通区间修改我们是创建1个线段树,树状数组套主席树的时候我们就创建log个线段 ...

  7. BZOJ 3205 [Apio2013]机器人 ——斯坦纳树

    腊鸡题目,实在卡不过去. (改了一下午) 就是裸的斯坦纳树的题目,一方面合并子集,另一方面SPFA迭代求解. 优化了许多地方,甚至基数排序都写了. 还是T到死,不打算改了,就这样吧 #include ...

  8. [ZJOI2007]棋盘制作 (单调栈,动态规划)

    题目描述 国际象棋是世界上最古老的博弈游戏之一,和中国的围棋.象棋以及日本的将棋同享盛名.据说国际象棋起源于易经的思想,棋盘是一个 8 \times 88×8 大小的黑白相间的方阵,对应八八六十四卦, ...

  9. Android 网络通信之Socket

    Android 网络通信之Socket 应用软件的网络通信无非就是Socket和HTTP,其中Socket又可以用TCP和UDP,HTTP的话就衍生出很多方式,基础的HTTP GET和POST请求,然 ...

  10. Resin Thread Dump

    [2015/08/25 20:50:13.254] {ThreadLauncher2[ThreadPool[system]]-1} Thread Dump generated Tue Aug 25 2 ...