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. cout的输出格式初探3

    #include <iostream> #include <iomanip> using namespace std; int main() { double f=2.0/3. ...

  2. mac下使用brew安装java等应用

    可以使用brew安装很多应用,比如java,idea,iterms,sublime brew tap caskroom/versions 将会安装新的brew仓库源brew cask install ...

  3. Android开发之Navigationdrawer导航抽屉功能的实现(源码分享)

    导航抽屉(navigationdrawer)是一个从屏幕左边滑入的面板,用于显示应用的主要导航项目.用户能够通过在屏幕左边缘滑入或者触摸操作栏的应用图标打开导航抽屉. 导航抽屉覆盖在内容之上,但不覆盖 ...

  4. C语言:使用realloc函数对malloc或者calloc动态分配的内存大小进行扩展

    #include<stdio.h> #include<stdlib.h> #include<time.h> typedef struct { char name[3 ...

  5. Kmeans聚类算法分析(转帖)

    原帖地址:http://www.opencvchina.com/thread-749-1-1.html       k-means是一种聚类算法,这种算法是依赖于点的邻域来决定哪些点应该分在一个组中. ...

  6. WhyDX9:翻写D3D红龙书中的程序

    之前写过一套学习OpenGL的框架:WhyGL,即然有了GL那也应该再写个学习D3D的框架:WhyDX9.两个程序的架构相同,然后这个程序是将D3D红龙那本书的DEMO翻写了一遍.先将可执行程序发一下 ...

  7. 最小均方算法(LMS Algorithm)理论及DSP实现

    LMS算法可认为是机器学习里面最基本也比较有用的算法,神经网络中对参数的学习使用的就是LMS的思想,在通信信号处理领域LMS也非常常见,比如自适应滤波器. 本文主要对LMS(Least Mean Sq ...

  8. vue组件级路由钩子函数介绍,及实际应用

    正如其名,vue-router 提供的导航钩子主要用来拦截导航,让它完成跳转或取消. 有多种方式可以在路由导航发生时执行钩子:全局的.单个路由独享的.或者组件级的. 一.全局钩子 你可以使用 rout ...

  9. IDA远程调试so库JNI_Onload函数

    JNI_OnLoad函数大概功能就是在程序加载so的时候,会执行JNI_OnLoad函数,做一系列的准备工作.很多时候,程序猿们会将一些重要信息放在此函数中,而不是通过某种事件来重复触发.包括说将反调 ...

  10. Jquery 获取table当前行内容

    $("a[name='checkOriginal']").click(function () { var parent = $(this).parent().parent().fi ...