LightOJ - 1079 Just another Robbery(背包)
来源:互联网 发布:2017网络交易法规 编辑:程序博客网 时间:2024/05/12 08:06
题目大意:给出一个概率P,和N个银行,再给出每个银行的被捕概率和钱的数量,问在被捕概率小于P的情况下,偷到的最多的钱
解题思路:用dp[i][j]表示前i个银行,偷盗了j的钱的最低被捕概率,接着进行背包
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int N = 110;const int M = 10010;const double esp = 1e-6;double p;int n, sum, cas = 1;int money[N];double caught[N], dp[N][M];void init() { scanf("%lf%d", &p, &n); sum = 0; for (int i = 1; i <= n; i++) { scanf("%d%lf", &money[i], &caught[i]); sum += money[i]; }}void solve() { memset(dp, -1, sizeof(dp)); dp[0][0] = 0; for (int i = 1; i <= n; i++) for (int j = 0; j <= sum; j++) { //第i个银行不抢 dp[i][j] = dp[i - 1][j]; //抢 if (j - money[i] >= 0 && (double)1 + dp[i - 1][j - money[i]] > esp) { if ((double)1 + dp[i][j] > esp) dp[i][j] = min(dp[i][j], dp[i - 1][j - money[i]] + (1 - dp[i - 1][j - money[i]]) * caught[i]); else dp[i][j] = dp[i - 1][j - money[i]] + (1 - dp[i - 1][j - money[i]]) * caught[i]; } } for (int i = sum; i >= 0; i--) if (p - dp[n][i] > esp) { printf("Case %d: %d\n", cas++, i); break; }}int main() { int test; scanf("%d", &test); while (test--) { init(); solve(); } return 0;}
0 0
- LightOJ - 1079 Just another Robbery(背包)
- LightOJ 1079 - Just another Robbery (01背包)
- LightOJ 1079 - Just another Robbery 【背包问题】
- 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 1079 - Just another Robbery (背包问题)
- LightOJ 1079Just another Robbery &&HDU 2955Robberies 01背包
- Just another Robbery LightOJ
- Just another Robbery LightOJ
- Linux Top 命令
- crazyflie2.0_crazyflie-firmware_LED指示灯
- JAXB基本使用
- OC Block相关
- hibernate配置文件注意点
- LightOJ - 1079 Just another Robbery(背包)
- VS2008编写ocx控件(使用了GDI+)注册时死锁,资源添加时VS奔溃
- fpga基础知识误点
- SQL实现将一个表的数据插入到另外一个表的代码
- [Django与表单]写一个简单的Django form表单处理
- 搞定webfigure标签
- 随机的力量(1) - The power of random two choices
- ARINC429数据总线简介
- poj 2418 Hardwood Species(Trie树)