1. 程式人生 > >獎勵關

獎勵關

getch header pair 要求 sep lin -- 十分 math

獎勵關

題目要求我們求出期望得分

發現$ 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;
}

獎勵關