
Initially, all the fluorescent lights are dark. For each switch, Matt will touch it with probability 1 .
As a curious gentleman, Matt wants to calculate E[X3], where X represents the number of bright lights at the end, E[X3] represents the expectation of cube of X.
Input
For each test case, the first line contains N, M (1 ≤ N, M ≤ 50), denoting the number of fluorescent lights (numbered from 1 to N ) and the number of switches (numbered from 1 to M ).
M lines follow. The i-th line begins with an integer Ki (1 ≤ Ki ≤ N ). Ki distinct integers lij(1 ≤ lij ≤ N ) follow, denoting the fluorescent lights that the i-th switch controls.
Output
E[X3] × 2M mod (109 + 7)
Sample Input
2
2 2
1 1
2 1 2
3 1
3 1 2 3
Sample Output
Case #1: 10
Case #2: 27
Hint
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int N=,Mod=(int)1e9+;
typedef long long LL;
LL dp[N][],op[N][N];
int T,cas,n,m;LL ans;
int main(){
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
memset(op,,sizeof(op));
for(int i=,k,x;i<=m;i++){
scanf("%d",&k);
while(k--){
scanf("%d",&x);
op[i][x]=;
}
}
ans=;
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
for(int k=;k<=n;k++){
memset(dp,,sizeof(dp));
dp[][]=;
for(int t=;t<=m;t++){
for(int p=;p<=;p++)
dp[t][p]=dp[t-][p];
int go=;
if(op[t][k])go+=;
if(op[t][j])go+=;
if(op[t][i])go+=;
for(int p=;p<=;p++)
(dp[t][p^go]+=dp[t-][p])%=Mod;
}
(ans+=dp[m][])%=Mod;
}
printf("Case #%d: %lld\n",++cas,ans);
}
return ;
}