xyz32768
2017-08-18 12:04:46
很明显是一道状压。
但这个模型存在问题:可能在第
所以,这里把定义换一下,
转移方程为:
对于任意一个
1、如果
所以此时
2、如果
而这里求的是期望值,上面求的东西覆盖了第
最后答案为
代码:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
inline int read() {
int res = 0; bool bo = 0; char c;
while (((c = getchar()) < '0' || c > '9') && c != '-');
if (c == '-') bo = 1; else res = c - 48;
while ((c = getchar()) >= '0' && c <= '9')
res = (res << 3) + (res << 1) + (c - 48);
return bo ? ~res + 1 : res;
}
const int M = 105, N = 17;
int K, n, p[N], sta[N];
double f[M][1 << 15];
void chkmax(double &a, double b) {a = max(a, b);}
int main() {
int i, j, k, x; K = read(); n = read();
for (i = 1; i <= n; i++) {
p[i] = read(); while (x = read())
sta[i] = sta[i] | (1 << x - 1);
}
for (i = K; i >= 1; i--) for (j = 0; j < (1 << n); j++) {
for (k = 1; k <= n; k++) if ((j & sta[k]) == sta[k])
f[i][j] += max(f[i + 1][j], f[i + 1][j | (1 << k - 1)] + p[k]);
else f[i][j] += f[i + 1][j];
f[i][j] /= n;
}
printf("%.6lf\n", f[1][0]);
return 0;
}