【BZOJ1076】[SCOI2008]奖励关【期望DP】【状压DP】

【题目链接】

写了忘发上来了。

/* Pigonometry */
#include <cstdio>
#include <algorithm>

using namespace std;

typedef double DB;

const int maxn = 20, maxk = 105, maxs = 1 << 16;

int n, k, s[maxn], w[maxn];
DB dp[maxk][maxs];

int main() {
	scanf("%d%d", &k, &n);
	for(int i = 1; i <= n; i++) {
		scanf("%d", &w[i]);
		while(1) {
			int x; scanf("%d", &x);
			if(!x) break;
			s[i] |= 1 << (x - 1);
		}
	}

	int S = 1 << n;
	for(int i = k; i >= 1; i--) for(int j = 0; j < S; j++) {
		for(int o = 1; o <= n; o++)
			if((j & s[o]) == s[o]) dp[i][j] += max(dp[i + 1][j], dp[i + 1][j | (1 << (o - 1))] + w[o]);
			else dp[i][j] += dp[i + 1][j];
		dp[i][j] /= n;
	}

	printf("%.6lf\n", dp[1][0]);
	return 0;
}


你可能感兴趣的:(【BZOJ1076】[SCOI2008]奖励关【期望DP】【状压DP】)