抢银行 扭向0 1
2016-05-03 12:57
169 查看
Problem V
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)Total Submission(s) : 24 Accepted Submission(s) : 8
[align=left]Problem Description[/align]
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.<br><br><center><img src=../../../data/images/con211-1010-1.jpg></center> <br>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.<br><br><br>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.
[align=left]Input[/align]
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 . <br>Bank j contains Mj millions, and the probability of getting caught from robbing it is Pj .
[align=left]Output[/align]
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.<br><br>Notes and Constraints<br> 0 < T <= 100<br> 0.0 <= P <= 1.0<br> 0
< N <= 100<br> 0 < Mj <= 100<br> 0.0 <= Pj <= 1.0<br> A bank goes bankrupt if it is robbed, and you may assume that all probabilities are independent as the police have very low funds.
[align=left]Sample Input[/align]
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
[align=left]Sample Output[/align]
2
4
6
关于抢银行的问题
上来先把失败全部转化为成功的概率
然后逆向dp
对所有的 价钱
分别求出抢到这个价钱最大成功概率
抢到这个价钱的概率
最后 取出 钱数最大概率能成功的 案例
#include<iostream> #include<string.h> #include<set> #include<stdio.h> #include<vector> #include<algorithm> #include<numeric> #include<math.h> #include<string.h> #include<sstream> #include<stdio.h> #include<string> #include<cstdlib> #include<algorithm> #include<iostream> #include<map> #include<queue> #include<iomanip> #include<cstdio> using namespace std; double pao[10000]; int a[10000]; double b[10000]; int main() { int t; scanf("%d",&t); while(t--) { memset(pao,0,sizeof(pao)); pao[0]=1; double t; int x; scanf("%lf %d",&t,&x); t=1-t; int i,j; int sum=0; for(i=1;i<=x;i++) { scanf("%d%lf",&a[i],&b[i]); b[i]=1-b[i]; sum=sum+a[i]; } for(i=1;i<=x;i++) { for(j=sum;j>=a[i];j--) { if(pao[j]<pao[j-a[i]]*b[i]) { pao[j]=pao[j-a[i]]*b[i]; } } } for(i=sum;i>=0;i--) { if((pao[i]-t)>0.000000001) {cout<<i<<endl; break; } } } return 0; }
相关文章推荐
- JavaScript权威指南 第二章 词法结构
- jQuery使用ajaxStart()和ajaxStop()方法
- 053(五十八)
- ARM920T及其MMU,Cache学习杂记(一)
- POJ 3450 Corporate Identity(后缀数组+二分)
- 8.PHP中原码反码介绍及位运算符应用
- 【追求进步】数组中重复的数字
- 053(五十七)
- 第十周项目一 阅读下面的定义,请说出在测试函数中不同情况的调用产生的结果(5 b)
- mojo 接口返回键值对的json格式
- Java 多线程编程学习(二)
- VS 2010 快捷键
- mojo 接口返回键值对的json格式
- mojo 接口返回键值对的json格式
- 7.PHP中的运算符2
- 移植gdb工具-远程调试qt程序
- 把本地代码同步到github
- PLSQL Developer连接64位oracle
- 0 1 背包
- Drawable资源——ShapeDrawable资源