01背包1004
来源:互联网 发布:全站仪数据.dat下载 编辑:程序博客网 时间:2024/05/30 23:43
Robberies
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 8 Accepted Submission(s) : 4
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
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
Bank j contains Mj millions, and the probability of getting caught from robbing it is Pj .
Output
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 <stdio.h>#include <algorithm>#include <string.h>using namespace std;double f[10000];int main(){ int T; while(cin>>T) { while(T--) { double m; int n; cin>>m>>n; int i,j; int a[105]; double b[105]; int sum=0; for(i=1;i<=n;i++) { cin>>a[i]>>b[i]; sum+=a[i]; } memset(f,0,sizeof(f)); f[0]=1; for(i=1;i<=n;i++) { for(j=sum;j>=a[i];j--) { f[j]=max(f[j],f[j-a[i]]*(1-b[i])); } } int z; for(i=sum;i>=0;i--) { if(f[i]>=1-m) { z=i; break; } } cout<<z<<endl; } } return 0;}
- 01背包1004
- 【背包专题】01背包
- 01背包,完全背包
- 01背包 完全背包
- 01背包/完全背包
- 01背包,完全背包
- 背包问题---01背包
- 背包入门--01背包
- 【背包专题】01背包
- 01背包,完全背包
- 01背包,完全背包, 多重背包
- 01背包,完全背包,多重背包
- 01背包、完全背包、多重背包详解
- 01背包,完全背包,多重背包
- 01背包、完全背包、多重背包
- 01背包、完全背包、多重背包
- 01背包、完全背包、多重背包
- 01背包、完全背包、多重背包
- Educational Codeforces Round 21 -DEG
- cookie 的简单使用
- Vuejs中nextTick()异步更新队列源码解析
- vs2013找不着mfc120d.lib咋办
- 面试问题(二)
- 01背包1004
- C# LINQ使用
- 如何输出程序段所运行时间
- 数据结构与算法(24)——堆习题
- 循环结构
- R-igarph实例操作(一)
- 深入浅出理解JAVA 8 Lambda表达式 Stream
- java 死锁产生原因及解锁
- 从命令行输入一个字符串!要求从中随机选择6个字符组成验证码!