HDU2955--Robberies--动态规划
来源:互联网 发布:企业邮箱搜索软件 编辑:程序博客网 时间:2024/06/05 02:33
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.
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 .
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.
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
30.04 31 0.022 0.033 0.050.06 32 0.032 0.033 0.050.10 31 0.032 0.023 0.05
Sample Output
246
#include <iostream>#include <cstdio>using namespace std;double dp[10008];double max(double a,double b){return a>b?a:b;}struct Bank{int money;double bz;double ts;}bank[108];int main(){int t;scanf("%d",&t);while(t--){double lowbz;int sum;scanf("%lf%d",&lowbz,&sum);for(int i=1;i<=sum;i++){scanf("%d%lf",&bank[i].money,&bank[i].bz);}for(int i=1;i<=sum;i++){bank[i].ts=1.0-bank[i].bz;}int maxmoney=0;for(int i=1;i<=sum;i++){maxmoney+=bank[i].money;}memset(dp,0,sizeof(dp));dp[0]=1.0;for(int i=1;i<=sum;i++){for(int j=maxmoney;j>=bank[i].money;j--)//仔细想想,这里必须从后往前。{dp[j]=max(dp[j],dp[j-bank[i].money]*bank[i].ts);}}for(int i=maxmoney;i>=0;i--){if(1-dp[i]<=lowbz){cout<<i<<endl;break;}}}return 0;}
- HDU2955--Robberies--动态规划
- HDU2955(动态规划背包)
- HDU2955 Robberies
- hdu2955-Robberies
- hdu2955 Robberies
- HDU2955 Robberies
- hdu2955 Robberies
- HDU2955-Robberies
- hdu2955 Robberies
- hdu2955 Robberies
- hdu2955 - Robberies
- hdu2955 Robberies
- HDU2955 Robberies
- HDU2955 Robberies
- HDU2955-Robberies
- hdu2955 Robberies
- HDU2955 Robberies
- Robberies||HDU2955
- ios 国际化(项目名和内容)
- 探索Android 下拉刷新效果的实现
- Silverlight5在Tomcat上的部署
- MotionEvent事件在onInterceptTouchEvent()、onTouchEvent()中的传递顺序
- libmad MP3解码
- HDU2955--Robberies--动态规划
- 获取iPhone通话记录(需越狱)
- C程序中内存布局&Union大小尾端
- Windows系统获取系统的启动时间
- javascript美化下拉框js
- AS3中的元数据标签
- 最好的 调试函数 dump 取自 thinkphp
- 适配器模式(Adepter)
- iphone获取本机电话号码 iPhone获取通讯录里电话号码