LightOJ 1079 Just another Robbery 概率dp
来源:互联网 发布:大数据相关上市公司 编辑:程序博客网 时间:2024/06/06 04:54
/* 题目描述:有n件物品,盗走第i件物品可以得到财产m[i],但同时有p[i]的概率被抓住,现要求从这n件物品中取走若干件, 使得得到的财产量最多,又要保证被抓住的概率小于P 思路:dp[i][j]表示到第i件物品时得到财产j时被抓住的概率最小值,则有 dp[i][j] = min(dp[i - 1][j] , dp[i - 1][j - m[i]] + (1 - dp[i][ j - m[i] ] ) * p[i]) min中第一项含义为从i - 1件中已经拿到了财产j,那么第i件不必冒风险去拿,所以dp[i][j] = dp[i - 1][j - 1], 第二项含义为从i-1 件中已经拿到了财产j - m[i] , 再拿走第i件就可以补全财产总量j,那么被抓到的概率等于在拿到j - m[i] 过程中被抓到的概率 + 在拿j - m[i]过程中未被抓到的概率 * 拿第i件物品时被抓到的概率*/#pragma warning(disable:4786)#pragma comment(linker, "/STACK:102400000,102400000")#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<stack>#include<queue>#include<map>#include<set>#include<vector>#include<cmath>#include<string>#include<sstream>#define LL long long#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i)#define mem(a,x) memset(a,x,sizeof(a))#define lson l,m,x<<1#define rson m+1,r,x<<1|1using namespace std;const int INF = 0x3f3f3f3f;const int mod = 1e9 + 7;const double PI = acos(-1.0);const double eps=1e-8;const int maxn = 1e4 + 5;double dp[maxn] , p[maxn];int m[maxn];int main(){ int n , T , kase = 0; double P; scanf("%d",&T); while(T--){ scanf("%lf%d",&P , &n); int sum = 0; for(int i = 1 ; i <= n ; i++){ scanf("%d%lf",&m[i],&p[i]); sum += m[i]; } for(int i = 0 ; i<= sum ; i++) dp[i] = INF; dp[0] = 0; sum = 0; int ans = - 1; for(int i = 1 ; i <= n ; i++ ){ sum += m[i] ; for(int j = sum ; j >= 1 ; j--){ if(j >= m[i] && (0 <= dp[j - m[i]]&&dp[j - m[i] ]<= 1)) dp[j] = min(dp[j - m[i]] + (1.0 - dp[j - m[i]] ) * p[i] , dp[j]); if(dp[j] < P) ans = max(ans , j); } } if(ans != -1) printf("Case %d: %d\n" , ++kase , ans ); else printf("Case %d: 0\n" , ++kase ); } return 0;}
0 0
- LightOJ 1079 Just another Robbery 概率dp
- LightOJ - 1079 Just another Robbery 概率 + dp
- 【LightOJ 1079】Just another Robbery(概率DP+背包)
- LightOJ - 1079 Just another Robbery 概率 + dp
- LightOJ-1079-Just another Robbery (概率dp)
- lightoj- 1079-Just another Robbery【DP】
- 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 Just another Robbery 1079 (01背包转换&概率)
- Just another Robbery(概率dp)
- Just another Robbery LightOJ
- Just another Robbery LightOJ
- Just another Robbery LightOJ
- Just another Robbery LightOJ
- 还在用Not in为什么不用 join
- Android N分屏(多窗口)适配
- 浮动及如何清除浮动
- 如何创建进程
- [342] Power of Four
- LightOJ 1079 Just another Robbery 概率dp
- leetcode 63. Unique Paths II
- Object-C面向对象编程
- 在linux下调用syscalls.h头文件
- 算法 给出一个数组,求连续相邻的最大面积
- 这是转载的 java反射机制与原理,原作者讲解的相对很通俗易懂
- 《文化苦旅》 and 工作初猎
- NKOI 3464 快速乘积
- 相对定位,绝对定位