Robberies

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 9563    Accepted Submission(s): 3575

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
 

思路: 这道题可以用o/1背包来解答,

思路是将被捕的概率转变为escape的概率,escape=1-catch;

所以抢一个bank,然后都能escape,则抢掉n个bank,逃跑的概率为  tol_escape=escape1*escape2*.....;

这样就可以求出最多能抢到的money啦....

讲的,若果还不明白的话,就再开下代码吧,估计既可以百分百理解了...

 #include<stdio.h>
#include<string.h>
#include<stdlib.h>
const int maxn=;
struct bank
{
int m;
float p;
};
bank sta[];
float dp[];
int main()
{
int test;
int toln,i,j,toll;
float tolp;
scanf("%d",&test);
while(test--)
{
scanf("%f%d",&tolp,&toln);
tolp=-tolp;
toll=;
for(i=;i<toln;i++)
{
scanf("%d%f",&sta[i].m,&sta[i].p);
sta[i].p=-sta[i].p; // scape
toll+=sta[i].m; //得到总容量
}
memset(dp,,sizeof(dp));
dp[]=;
for(i=;i<toln;i++)
{
for(j=toll;j>=sta[i].m;j--)
{
if(dp[j]<dp[j-sta[i].m]*sta[i].p)
{
dp[j]=dp[j-sta[i].m]*sta[i].p;
}
}
}
int ans=;
for(j=toll;j>=;j--)
{
if(dp[j]>=tolp)
{
ans=j;
break;
}
}
printf("%d\n",ans);
} return ;
}

HDUOJ---2955 Robberies的更多相关文章

  1. HDOJ 2955 Robberies (01背包)

    10397780 2014-03-26 00:13:51 Accepted 2955 46MS 480K 676 B C++ 泽泽 http://acm.hdu.edu.cn/showproblem. ...

  2. HDU 2955 Robberies 背包概率DP

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

  3. HDOJ.2955 Robberies (01背包+概率问题)

    Robberies 算法学习-–动态规划初探 题意分析 有一个小偷去抢劫银行,给出来银行的个数n,和一个概率p为能够逃跑的临界概率,接下来有n行分别是这个银行所有拥有的钱数mi和抢劫后被抓的概率pi, ...

  4. Hdu 2955 Robberies 0/1背包

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

  5. [HDU 2955]Robberies (动态规划)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 题意是给你一个概率P,和N个银行 现在要去偷钱,在每个银行可以偷到m块钱,但是有p的概率被抓 问 ...

  6. hdu 2955 Robberies 0-1背包/概率初始化

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

  7. hdu 2955 Robberies

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

  8. hdoj 2955 Robberies

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

  9. hdu 2955 Robberies 背包DP

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

  10. HDU 2955 Robberies(01背包)

    Robberies Problem Description The aspiring Roy the Robber has seen a lot of American movies, and kno ...

随机推荐

  1. Android 系统服务一览表

    在<Zygote进程[3]--SystemServer的诞生>一文中介绍了SystemServer的诞生,本文来看一下SystemServer中初始化的系统服务. 1.AccountMan ...

  2. spark调优经验(待续)

    spark调优是须要依据业务须要调整的,并非说某个设置是一成不变的,就比方机器学习一样,是在不断的调试中找出当前业务下更优的调优配置.以下零碎的总结了一些我的调优笔记. spark 存储的时候存在严重 ...

  3. QT QCharts QScatterSeries 空心点阵图,鼠标移动到上面显示数值,鼠标移开数值消失

    在最近接到的需求是这样的,画一个折线图,关键点使用空心的圆点标识出来,鼠标移动到关键点上,显示出当前数值:鼠标移走数值消失. 我们遇到这个需求的时候,第一时间就会想到使用 QLineSeries 画折 ...

  4. Jquery中parent()和parents()

    一.parent()方法 此方法取得匹配元素集合中每个元素的紧邻父元素,也就是第一级父元素,而不是所有的祖先元素.所取得的父元素集合也可以使用表达式进行筛选. 二.parents()方法 此方法取得一 ...

  5. Java方法重写与方法重载

    方法重载:发生在同一个类中,方法名相同方法形参列表不同就会重载方法. 方法重写:发生在继承当中,如果子的一个类方法与父类中的那个方法一模一样(方法名和形参列表一样),那么子类就会重写父类的方法. 方法 ...

  6. 默认网关和默认路由 —— Cisco CCNA – Default Gateway & Default Routes

    原文:https://www.certificationkits.com/cisco-certification/ccna-articles/cisco-ccna-intro-to-routing-b ...

  7. WordPress 后台添加额外选项字段到常规设置页面

    有时候我们需要添加一些额外的设置选项到常规设置(后台 > 设置 > 常规)页面,下面是一个简单的范例: 直接添加到主题的 functions.php 即可:   /*** WordPres ...

  8. cognos report上钻下钻报表处理方法(1)

    cognos  report开发中追溯行为,也可以称为上钻下钻行为大致遇到了两种情况 第一种:根据当前报表样式在维度范围内上钻下钻. 第二种:给追溯行为指定报表,传递参数. 可能还有其他情况,这里就不 ...

  9. 【精】C语言之变量存储类型

  10. SQL Server 附加数据库提示5120错误

    怎么样是不是跟你的错误是一样的,心里是不是有点小激动? T_T 终于有办法了!!!! 第一步先关掉你的SQLserver 然后在菜单上找找到SQLSERVER右键选择“以管理员运行” 第二步给你的数据 ...