HDU 2955 Roberies 背包问题
来源:互联网 发布:黑马程序员上课时间表 编辑:程序博客网 时间:2024/06/05 02:46
疑问点:如何转化成0-1背包问题,有点不好理解,先打个大大的问号???
上限概率转化为最小的安全概率即p=1-p; 被活捉的概率为pj,安全概率即为pj=1-pj; 定义的容量为M=sumv,对应的钱数为M1,M2,M3...,求最大的安全概率,且要求安全概率大于p;
#include <iostream>#include <stdio.h>#include <algorithm>#include <math.h>#define MAXN 101#define MAXV 10001using namespace std; int cost[MAXV]; double weight[MAXV],d[MAXV];int main(){ int t,n,sumv; scanf("%d",&t); double p; while(t--) { sumv=0; scanf("%lf%d",&p,&n); p=1-p; for(int i=0;i<n;i++) { scanf("%d%lf",&cost[i],&weight[i]); weight[i]=1-weight[i]; sumv+=cost[i]; } for(int i=0;i<=sumv;i++) d[i]=0; d[0]=1; for(int i=0;i<n;i++) { for(int j=sumv;j>=cost[i];j--) { d[j]=max(d[j],d[j-cost[i]]*weight[i]); } } //bool flag=false; for(int i=sumv;i>=0;i--) { if(d[i]-p>0.0000000001) { printf("%d\n",i); break; } } } return 0;}
0 0
- HDU 2955 Roberies 背包问题
- HDU-2955 背包问题
- hdu 2955 背包问题
- hdu 2955 01背包问题
- hdu 2955(DP背包问题)
- 【HDU 2955】【背包问题】Robberies
- HDU 2955(0-1背包问题)
- hdu 2955 Robberies 01背包问题
- [HDU 2955] Robberies (01背包问题)
- HDU 2955(Robberies)0-1背包问题
- HDU 2955 Robberies(01背包问题)
- hdu 2955 Robberies 01背包问题
- hdu 2955(01背包问题)Robberies
- HDU 2955 Robberies(01背包问题)
- HDU 1171 背包问题
- HDU 1059 背包问题
- hdu 2126背包问题
- hdu 1864 背包问题
- 为元素文字高亮关键字
- C#彩色艺术化二维码样式设计(仅说思路)
- cocos2d-x 3.1搭建问题
- Git 学习笔记
- 深入浅出NodeJS——异步I/O
- HDU 2955 Roberies 背包问题
- margin 重叠
- QListView ------ Model-View-Control(MVC)架构(1)
- 日志
- 在.net(C#)中随机生成较深的颜色
- 博客&ACM新人
- 冷静客观能理解看女人反垄断法你了
- URAL1901贪心
- 细说java中Map的两种迭代方式