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. FizzBuzzWhizz问题python解法

    FizzBuzzWhizz 你是一名体育老师,在某次课距离下课还有五分钟时,你决定搞一个游戏.此时有100名学生在上课.游戏的规则是: 1. 你首先说出三个不同的特殊数,要求必须是个位数,比方3.5. ...

  2. EMC ViPR all in one page

    EMC ViPR 2.0 Product Documentation Index https://community.emc.com/docs/DOC-35557

  3. input框设置onInput事件只能输入数字,能兼容火狐IE9

    使用onInput()事件 onInput()是 HTML5 的标准事件,对于检测 textarea, input:text, input:password 和 input:search 这几个元素通 ...

  4. Android -- Drawable && Bitmap

    Bitmap转Drawable Bitmap bm=xxx; BitmapDrawable bd=new BitmapDrawable(bm); 因为BtimapDrawable是Drawable的子 ...

  5. ajax局部刷新一个div下的jsp

    用AJAX刷新一个DIV中的jsp内容 <script type="text/javascript"> var xmlhttp; function startrefre ...

  6. HDU 3535 AreYouBusy(混合背包)

    HDU3535 AreYouBusy(混合背包) http://acm.hdu.edu.cn/showproblem.php?pid=3535 题意: 给你n个工作集合,给你T的时间去做它们.给你m和 ...

  7. 5. How to set up a Activity

    1. Create a new xml in "layout" folder "splah.xml" <?xml version="1.0&qu ...

  8. Android 色彩设计理念

    色彩 色彩从当代建筑.路标.人行横道以及运动场馆中获取灵感.由此引发出大胆的颜色表达激活了色彩,与单调乏味的周边环境形成鲜明的对照. 强调大胆的阴影和高光.引出意想不到且充满活力的颜色. 色样 – 0 ...

  9. linux pdb调试总结

    1.首先gdb编译: gcc -g xxx.c -o xxx 2.然后 gdb xxx进入调试 break 行号 加入断点 (1)然后run就能够跑到下一个断点 (2)step(或s)单步跟踪 (3) ...

  10. WebService 与 Socket 区别

    一.WebService 1.什么是WebService Web Service(WEB服务)能够快捷和方便地综合结合各种系统.商务和任何应用平台.利用最新的Web Service 标准能够使任何软件 ...