[SCOI2008]奖励关 + 状压动归 + 数学期望
Code:
#include<cstdio> #include<algorithm> using namespace std; const int maxn = 20; double f[102][1 << maxn]; int score[maxn], state[maxn], pos[maxn],n, m, tmp ; int main(){ for(int i = 1;i <= 16; ++i) pos[i] = (1 << (i - 1)); scanf("%d%d",&n,&m); for(int i = 1;i <= m; ++i) { scanf("%d%d",&score[i],&tmp); while(tmp){ state[i] += pos[tmp]; scanf("%d",&tmp); } } for(int i = n;i >= 1; --i) for(int j = 0;j <= pos[m + 1]; ++j) { for(int k = 1;k <= m; ++k) if((state[k] & j) == state[k]) f[i][j] += max(f[i+1][j], f[i+1][j|pos[k]] + score[k]); else f[i][j] += f[i + 1][j]; f[i][j] /= m; } printf("%.6lf",f[1][0]); return 0; }