<SCOI2008>奖励关
emmm第一道期望dp+个状压
真有趣..
#include<cstdio> #include<iostream> #include<cstring> #include<algorithm> #define max(a,b) (a>b?a:b) #define rint register int template <class T>inline void read(T &X) { X=0;int W=0;char ch=0; while(!isdigit(ch))W|=ch=='-',ch=getchar(); while(isdigit(ch))X=(X<<3)+(X<<1)+(ch^48),ch=getchar(); X=W?-X:X;return; } int K,n,maxn,need[55]; double ans=0,p[20],dp[55][1<<16]; int main() { read(K),read(n); maxn=(1<<n)-1; for(rint i=1;i<=n;++i) { scanf("%lf",&p[i]); while(1) { int x; read(x); if(!x)break; need[i]=need[i]|(1<<x-1); } } for(rint i=K;i>0;--i) { for(rint s=0;s<=maxn;++s)//枚举状态 { for(rint j=1;j<=n;++j)//枚举可能的物品种类 { if((s&need[j])!=need[j]) {dp[i][s]+=dp[i+1][s];continue;} dp[i][s]+=max(dp[i+1][s],dp[i+1][s|(1<<j-1)]+p[j]); } dp[i][s]/=n; } } printf("%.6lf\n",dp[1][0]); return 0; }