LightOJ 1079 - Just another Robbery 【背包问题】
来源:互联网 发布:北极熊团 知乎 编辑:程序博客网 时间:2024/06/06 05:43
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1079
题意:
给你一些银行的存储金钱的数目及被抓的概率,若被抓总概率不超过p的话,问不被抓的条件下最多可以抢多少钱?
思路:
对于一个银行,可以抢或者不抢,于是想到了背包。
代码:
#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>#include <string.h>#include <string>using namespace std;double p;int n;int a[110];double b[110];double dp[11000];int main(){ int T; scanf("%d", &T); for (int t = 1;t <= T;t++) { memset(dp, 0, sizeof(dp)); scanf("%lf%d", &p, &n); int sum = 0; for (int i = 1;i <= n;i++) { scanf("%d%lf", &a[i], &b[i]); sum += a[i]; } dp[0] = 1; for (int i = 1;i <= n;i++) { for (int j = sum;j >= a[i];j--) { dp[j] = max(dp[j], dp[j - a[i]] * (1 - b[i])); } } int ans = 0; for (int i = 0;i <= sum;i++) { if (1 - dp[i] < p) ans = max(i, ans); } printf("Case %d: %d\n", t, ans); } return 0;}
0 0
- LightOJ 1079 - Just another Robbery 【背包问题】
- LightOJ 1079 - Just another Robbery (背包问题)
- LightOJ - 1079 Just another Robbery(背包)
- LightOJ 1079 - Just another Robbery (01背包)
- lightoj 1079 - Just another Robbery 01背包
- lightOJ 1079 Just another Robbery
- lightoj 1079 - Just another Robbery
- lightoj 1079 Just another Robbery
- LightOJ 1079 Just another Robbery
- 【lightoj 1079 Just another Robbery】
- LightOJ 1079 Just another Robbery
- LightOJ 题目1079 Just another Robbery(01背包)
- lightoj Just another Robbery 1079 (01背包转换&概率)
- lightoj 1079 - Just another Robbery(01背包)
- 【LightOJ 1079】Just another Robbery(概率DP+背包)
- LightOJ 1079Just another Robbery &&HDU 2955Robberies 01背包
- Just another Robbery LightOJ
- Just another Robbery LightOJ
- POJ【3630】Phone List
- GBDT 梯度下降决策树
- 深度学习R(1):从零开始建立完全连接的神经网络
- linux c 多线程编程总结
- 华为OJ 字符串分割
- LightOJ 1079 - Just another Robbery 【背包问题】
- oracle连接查询
- UI 画图四(画板画图)作业
- 这几天来重学Java的感受
- 事件之消息邮箱
- C#操作目录和文件
- RANSAC
- 专业化与大众化
- Integer to Roman