[BZOJ1076][SCOI2008]奖励关[状压DP+概率期望]

\(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; 
}
posted @ 2018-12-28 16:52  QvvQ  阅读(200)  评论(0编辑  收藏  举报