/*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. SignalR的简单实现

    1创建mvc的空项目 2添加文件夹Counters放在里面的类用于封装性能计数器 3创建PerfCounterWrapper类用于封装性能计数器的实体 using System; using Syst ...

  2. 一款基于jQuery多图切换焦点图插件

    这次要给大家分享的也是一款jQuery图片滑块插件,之前有介绍过不少实用的jQuery焦点图插件和jQuery图片滑块插件,比如jQuery左侧Tab切换的图片滑块插件.它的特点是可以同时切换多张图片 ...

  3. LeetCode29 Divide Two Integers

    题目: Divide two integers without using multiplication, division and mod operator. If it is overflow, ...

  4. c++ 设计模式8 (Factory Method 工厂方法)

    5. “对象创建”类模式 通过“对象创建”类模式绕开new,来避免对象创建(new)过程中所导致的紧耦合(依赖具体类),从而支持对象创建的稳定.它是接口抽象之后的第一步工作. 5.1 工厂方法 动机: ...

  5. WEB免费打印控件推荐

    在WEB系统中,打印的确是个烦人的问题. 要么自己开发打印控件,如果项目时间紧,肯定来不及. 要么购买成熟的打印控件,如果是大项目可以考虑,但如果项目只有几K到1.2W之间,这就麻烦了. 前段时间有机 ...

  6. Phone List

    Problem Description Given a list of phone numbers, determine if it is consistent in the sense that n ...

  7. mvc3.0 +linq 操作数据库中表的数据(ps:本人菜鸟刚学)

    1:添加控制器类文件HomeController.cs其代码如下: using System; using System.Collections.Generic; using System.Linq; ...

  8. nginx +lua +redis 构建自动缓存系统

    一. nginx环境搭建 第一步下载 LuaJIT-2.0.4.tar.gz http://luajit.org/download/LuaJIT-2.0.4.tar.gz安装 make &&a ...

  9. 【Java线程池快速学习教程】

    1. Java线程池 线程池:顾名思义,用一个池子装载多个线程,使用池子去管理多个线程. 问题来源:应用大量通过new Thread()方法创建执行时间短的线程,较大的消耗系统资源并且系统的响应速度变 ...

  10. Android必会小功能总结

    1.获取屏幕尺寸.密度等信息. 1)最常用的方法: WindowManager windowManager = getWindowManager(); Display display = window ...