Light OJ 1079 Just another Robbery (概率+背包)
来源:互联网 发布:知乎书店 编辑:程序博客网 时间:2024/05/27 14:13
解析:
dp[i][j]为考虑前i个银行,获得j元,不被逮捕的最大概率。
状态转移方程:dp[i][j] = max(dp[i-1][j],dp[i-1][j-a[i]]*(1-p[i]));
[code]:
#include<cstdio>#include<cstring>#include<cmath>#include<cstdlib>#include<algorithm>using namespace std;const double eps = 1e-7;int n,a[105];double m,dp[10005],p[105];// dp[i][j] = max(dp[i-1][j],dp[i-1][j-a[i]]*(1-p[i]));int main(){ int i,j,cas,T; scanf("%d",&cas); for(T = 1;T <= cas;T++){ scanf("%lf%d",&m,&n); int sum = 0; for(i = 0;i < n;i++){ scanf("%d%lf",&a[i],&p[i]); sum += a[i]; } memset(dp,0,sizeof(dp)); dp[0] = 1; for(i = 0;i < n;i++){ for(j = sum;j >= a[i];j--) dp[j] = max(dp[j],dp[j-a[i]]*(1-p[i])); } int ans; for(j = sum;j >= 0;j--) if(dp[j]>1-m||fabs(1-m-dp[j])<eps){ ans = j; break; } printf("Case %d: %d\n",T,ans); } return 0;}
0 0
- Light OJ 1079 Just another Robbery (概率+背包)
- light oj 1079 - Just another Robbery 【01背包】
- lightoj Just another Robbery 1079 (01背包转换&概率)
- 【LightOJ 1079】Just another Robbery(概率DP+背包)
- LightOJ1079 Just another Robbery 01背包、概率
- LightOJ 1079 Just another Robbery 概率dp
- LightOJ - 1079 Just another Robbery(背包)
- LightOJ 1079 - Just another Robbery (01背包)
- LightOJ 1079 - Just another Robbery 【背包问题】
- lightoj 1079 - Just another Robbery 01背包
- LightOJ1079---Just another Robbery (概率做01背包)
- LightOJ1079---Just another Robbery (概率牌01背包问题)
- hdu 2955 Robberies + LightOJ 1079 Just another Robbery (01背包 概率)
- LightOJ - 1079 Just another Robbery 概率 + dp
- LightOJ - 1079 Just another Robbery 概率 + dp
- LightOJ-1079-Just another Robbery (概率dp)
- LightOJ 题目1079 Just another Robbery(01背包)
- lightoj 1079 - Just another Robbery(01背包)
- Java认证考试实例疑难辨析(4)
- 2016蓝桥杯算法训练——未名湖边的烦恼
- hdoj 5621 KK's Point 【数学】
- cocos2d-x3.3 PageView常用成员函数
- 百岁老人(有照片)
- Light OJ 1079 Just another Robbery (概率+背包)
- 线段树常见套路
- 1023. 组个最小数 (20)
- Elasticsearch进化史
- HDU——2056Rectangles(几何计算)
- PHP---APP笔记
- BNUOJ 51275 道路修建 Large(并查集)
- hdoj 5623 KK's Number 【dp】
- ElasticSearch中的一些基本概念