bzoj 1076: [SCOI2008]奖励关【状压dp+概率dp】

设f[i][s]为前i步,选的礼物集合为s的方案数,然而并不会转移……
看了hzwer的blog,发现要倒着转移,然后答案就是f[1][0]
妙啊

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=15;
int n,m,a[N],p[N];
double f[105][40005];
int read()
{
	int r=0,f=1;
	char p=getchar();
	while(p>'9'||p<'0')
	{
		if(p=='-')
			f=-1;
		p=getchar();
	}
	while(p>='0'&&p<='9')
	{
		r=r*10+p-48;
		p=getchar();
	}
	return r*f;
}
int main()
{
	m=read(),n=read();
	for(int i=1;i<=n;i++)
	{
		a[i]=read();
		int x=read();
		while(x)
		{
			p[i]|=(1<<(x-1));
			x=read();
		}
	}
	for(int i=m;i>=1;i--)
		for(int s=0,len=1<<n;s<len;s++)
		{
			for(int j=1;j<=n;j++)
				if((p[j]&s)==p[j])
				   f[i][s]+=max(f[i+1][s],f[i+1][s|(1<<(j-1))]+a[j]);
				else 
					f[i][s]+=f[i+1][s];
			f[i][s]/=n;
		}
	printf("%.6f\n",f[1][0]);
	return 0;
}
posted @ 2018-09-27 16:24  lokiii  阅读(121)  评论(0编辑  收藏  举报