/*Robberies

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 13854 Accepted Submission(s): 5111 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 Source
IDI Open 2009 */
//0-1背包 公式:dp[i] = max(dp[i], dp[i-c]*(1-rp))
#include <cstdio>
#include <cstring>
const int maxn = + ;
double p, pj[maxn], dp[maxn];
int n, mj[maxn], sum;
double Max(double a, double b)
{
return a > b ? a : b;
}
void ZeroOnePack(int m, double rp)
{
for(int i = sum; i >= m; i--){
dp[i] = Max(dp[i], dp[i-m]*(-rp));
}
} int main()
{
int t;
while(~scanf("%d", &t)){
while(t--){
scanf("%lf%d", &p, &n);
sum = ;
for(int i = ; i < n; i++){
scanf("%d%lf", &mj[i], &pj[i]);
sum += mj[i];
}
memset(dp, , sizeof(dp));
dp[] = ;
for(int i = ; i < n; i++)
ZeroOnePack(mj[i], pj[i]);
for(int i = sum; i >= ; i--)
if(dp[i] > -p){
printf("%d\n", i); break;
}
}
}
return ;
}

hdu 2955 Robberies 0-1背包/概率初始化的更多相关文章

  1. Hdu 2955 Robberies 0/1背包

    Robberies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  2. HDU 2955 Robberies(0-1背包)

    http://acm.hdu.edu.cn/showproblem.php?pid=2955 题意:一个抢劫犯要去抢劫银行,给出了几家银行的资金和被抓概率,要求在被抓概率不大于给出的被抓概率的情况下, ...

  3. HDU 2955 Robberies (01背包,思路要转换一下,推荐!)

    题意: 小A要去抢劫银行,但是抢银行是有风险的,因此给出一个float值P,当被抓的概率<=p,他妈妈才让他去冒险. 给出一个n,接下来n行,分别给出一个Mj和Pj,表示第j个银行所拥有的钱,以 ...

  4. hdu 2955 Robberies(01背包)

    Robberies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  5. HDU 2955 Robberies【01背包】

    解题思路:给出一个临界概率,在不超过这个概率的条件下,小偷最多能够偷到多少钱.因为对于每一个银行都只有偷与不偷两种选择,所以是01背包问题. 这里有一个小的转化,即为f[v]代表包内的钱数为v的时候, ...

  6. HDU 2955 Robberies 背包概率DP

    A - Robberies Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submi ...

  7. HDU 2955 变形较大的01背包(有意思,新思路)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 Robberies Time Limit: 2000/1000 MS (Java/Others) ...

  8. hdu 2955 Robberies(概率背包)

    Robberies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  9. HDU 2955 Robberies(概率DP,01背包)题解

    题意:给出规定的最高被抓概率m,银行数量n,然后给出每个银行被抓概率和钱,问你不超过m最多能拿多少钱 思路:一道好像能直接01背包的题,但是有些不同.按照以往的逻辑,dp[i]都是代表i代价能拿的最高 ...

随机推荐

  1. 总结下cocopods的安装

    一:CocoaPods是什么? 当你开发iOS应用时,会经常使用到很多第三方开源类库,比如JSONKit,AFNetWorking等等.可能某个类库又用到其他类库,所以要使用它,必须得另外下载其他类库 ...

  2. UVA 1069 - Always an integer(数论)

    1069 - Always an integer 题意:给定一个多项式,推断是否总是整数 思路:LRJ大白上的例题,上面给出了证明,仅仅要1到k + 1(k为最高次数)带入方程都是整数,那么整个方程就 ...

  3. javascript代码解释执行过程

    javascript是由浏览器解释执行的脚本语言,不同于java c,需要先编译后运行,javascript 由浏览器js解释器进行解释执行,总的过程分为两大块,预编译期和执行期 下面的几个demo解 ...

  4. oc-16-set,get方法

    S.h #import <Foundation/Foundation.h> /** 解决方案: 1.不用@public修饰 2.我们对象有访问和设置成员变量的两种操作 1>设置值 p ...

  5. 面试感悟----一名3年工作经验的程序员应该具备的技能 JAVA 必读书

    http://www.cnblogs.com/xrq730/p/5260294.html#3470685 http://www.cnblogs.com/xrq730/p/4994545.html

  6. Linux网卡高级命令、IP别名及多网卡绑定 转

    http://www.cnblogs.com/xiaoluo501395377/archive/2013/05/26/3100065.html 本篇随笔将详细讲解Linux系统的网卡高级命令.IP别名 ...

  7. 何查看Tomcat版本信息

    转自:http://dengjianqiang200.blog.163.com/blog/static/65811920094644354148/ 一般来说,在tomcat启动时就会有版本信息,如: ...

  8. Java再学习——sleep(), wait(), notify(), notifyAll()

    首先一点就是Thread.sleep(long millis)方法是Thread类的静态方法,其他三个wait(), notify()和notifyAll()都是Object类的方法. sleep(l ...

  9. UIView的生命周期

    一. 大体流程: (loadView/nib)文件来加载view到内存-->viewDidLoad函数进一步初始化这些view-->内存不足时, 调用viewDidUnload函数释放vi ...

  10. C# unix时间戳转换

    场景:由于业务需要和java 开发的xxx系统对接日志,xxx系统中用“1465195479100” 来表示时间,C# 里面需要转换做一下逻辑处理,见代码段. C#获取的unix时间戳是10位,原因是 ...