首页 > 其他 > 详细

[BZOJ1076][SCOI2008]奖励关(概率DP)

时间:2018-06-03 16:43:16      阅读:216      评论:0      收藏:0      [点我收藏+]

Code

#include <cstdio>
#include <algorithm>
#include <cstring>
#define N 110
#define db double 
using namespace std;

int n,m,nd[N],v[N];
db f[N][1<<16];

inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
    while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
    return x*f;
}

db DP(int i,int S){
	if(i>m) return 0;
	db &tmp=f[i][S];
	if(tmp+1e9>1e-9) return tmp;
	tmp=0;
	for(int j=1;j<=n;++j)
		if((S|nd[j])==S)
			tmp+=max(DP(i+1,S),DP(i+1,S|(1<<(j-1)))+v[j]);
		else tmp+=DP(i+1,S);	
	tmp/=n;
	return tmp;
}

int main(){
	m=read(),n=read();
	for(int i=1;i<=n;++i){
		v[i]=read();
		for(int x=read();x!=0;x=read()) nd[i]|=(1<<(x-1));
	}
	for(int i=0;i<=m;++i)for(int j=0;j<(1<<n);++j)f[i][j]=-2e9;
	printf("%.6lf\n",DP(1,0));
}

 

[BZOJ1076][SCOI2008]奖励关(概率DP)

原文:https://www.cnblogs.com/void-f/p/9129442.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!