标签:algorithm lse oid putchar std while clu || mat
题目要求我们求出期望得分
发现$ n $十分小
考虑状压
设状态\(f[i][j]\)表示前i关.状态为j的期望值
然后期望倒推就ok了.
最后答案是\(f[1][0]\)
/*header*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#define rep(i , x, p) for(int i = x;i <= p;++ i)
#define sep(i , x, p) for(int i = x;i >= p;-- i)
#define gc getchar()
#define pc putchar
#define ll long long
#define mk make_pair
#define fi first
#define se second
using std::min;
using std::max;
using std::swap;
inline int gi() {
int x = 0,f = 1;char c = gc;
while(c < '0' || c > '9') {if(c == '-')f = -1;c = gc;}
while(c >= '0' && c <= '9') {x = x * 10 + c - '0';c = gc;}return x * f;
}
void print(int x) {
if(x < 0) pc('-') , x = -x;
if(x >= 10) print(x / 10);
pc(x % 10 + '0');
}
const int maxN = 100 + 7;
double f[maxN][32800];
int need[maxN] ,a[maxN];
int main() {
int k = gi() , n = gi();
rep(i , 1, n) {
a[i] = gi();
while(true) {
int x = gi();if(!x) break;
need[i] |= (1 << x - 1);
}
}
sep(i , k, 1) {
rep(j , 0, (1 << n) - 1) {
rep(l , 1, n) {
if(!( ( ~j ) & need[l]) ) {
f[i][j] += max(f[i + 1][j] , f[i + 1][j | (1 << (l - 1))] + a[l]);
}
else f[i][j] += f[i + 1][j];
}
f[i][j] /= n;
}
}
printf("%.6lf\n", f[1][0]);
return 0;
}
标签:algorithm lse oid putchar std while clu || mat
原文地址:https://www.cnblogs.com/gzygzy/p/10262021.html