n<=15 直接状压 , f[i][j]表示到i , 1--i-1选了哪些 的期望分值
#include<bits/stdc++.h>
#define N 1<<15
#define K 105
using namespace std;
int n,k,s[K],val[K]; double f[K][N],inf;
double dfs(int now,int S){
if(now > k) return 0;
if(f[now][S] != inf) return f[now][S];
double ans = 0;
for(int i=1;i<=n;i++){
if((s[i]&S) == s[i]) ans += max(dfs(now+1 , S) , dfs(now+1 , S|(1<<(i-1))) + val[i]);
else ans += dfs(now+1 , S);
}return f[now][S] = (ans/n);
}
int main(){
memset(f,127,sizeof(f)); inf = f[0][0];
scanf("%d%d",&k,&n);
for(int i=1;i<=n;i++){
int x; scanf("%d",&val[i]);
while(scanf("%d",&x) && x!=0) s[i] |= (1<<(x-1));
}
printf("%0.6lf",dfs(1,0)); return 0;
}