[BZOJ1076][SCOI2008]獎勵關[狀壓DP+概率期望]
阿新 • • 發佈:2018-12-28
i+1 for += int clas digi 要求 lin sco
\[f[i][j]\] 表示第1到i-1輪寶物是否取過的狀態是j,第i輪到最後一輪的最大得分。
這樣設計狀態並且倒著推,可以保證不合法的狀態是0,不會造成影響
\[nd[i]\]表示第i個物品要求的狀態
#include <bits/stdc++.h> using namespace std; typedef long long LL; #define lop(i,a,b) for(register int i = (a); i <= (b); ++i) #define dlop(i,a,b) for(register int i = (a); i >= (b); --i) #define eps (1e-7) inline int read(){ register int c = getchar(), x = 0, f = 1; while(!isdigit(c)) {if (c == '-') f = -1; c = getchar();} while(isdigit(c)) x = (x<<3)+(x<<1)+(c^48), c = getchar(); return x * f; } double f[105][65536]; int a[16], w[16], s[16], n, m, k, nd[16]; int main(void){ scanf("%d%d", &n, &m); for(int i = 1; i <= m; ++i) { int tmp; scanf("%d%d", &w[i], &tmp); while(tmp) nd[i] |= (1<<tmp-1), scanf("%d", &tmp); } for(int i = n; i; --i) { for(int j = 0; j < (1<<m); f[i][j] /= m, ++j) { for(int k = 1; k <= m; ++k) { if (f[i+1][j] >= f[i+1][j|(1<<k-1)] + w[k] || (nd[k]&j) != nd[k]) f[i][j] += f[i+1][j]; else f[i][j] += f[i+1][j|(1<<k-1)] + w[k]; } } } printf("%.6lf", f[1][0]); return 0; }
[BZOJ1076][SCOI2008]獎勵關[狀壓DP+概率期望]