Fluorescent
Time Limit: 3000/3000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)
Total Submission(s): 937 Accepted Submission(s): 477
Problem Description
Matt, a famous adventurer who once defeated a pack of dire wolves alone, found a lost court. Matt finds that there are N fluorescent lights which seem to be the stars from the firmament. What’s more, there are M switches that control these fluorescent lights. Each switch is connected to a group of lights. When Matt touches a switch, all the lights connected to it will change their states (turning the dark on, turning the bright off).
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.
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
The first line contains only one integer T , which indicates the number of test cases.
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.
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
For each test case, output a single line “Case #x: y”, where x is the case number (starting from 1) and y is the answer. To avoid rounding error, the answer you should output is:
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
For the first sample, there’re 4 possible situations:
All the switches is off, no light is bright, X^3 = 0.
Only the first switch is on, the first light is bright, X^3 = 1.
Only the second switch is on, all the lights are bright, X^3 = 8.
All the switches is on, the second lights are bright, X^3 = 1.
Therefore, the answer is E[X^3] × 2^2 mod (10^9 + 7) = 10.
For the second sample, there’re 2 possible situations:
The switches is off, no light is bright, X^3 = 0.
The switches is on, all the lights are bright, X^3 = 27.
Therefore, the answer is E[X^3] × 2^1 mod (10^9 + 7) = 27.
Source
Recommend
liuyiding
题意:一些灯和一些开关,每个开关都能控制一部分灯,求在开关的所有状态亮灯个数立方和;
题解:
View Code
ans=sigma(x^3) ,把x^3拆开就是(x1+x2+...xn)*(x1+x2+...+xn)*(x1+x2+...+xn),ans=sigma(∑∑∑(xi*xj*xk))=∑∑∑(sigma(使得xixjxk同时亮的状态数))
这样可以避免枚举2^m个状态,因为只有三个灯亮,状态为2^3
参考代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define mem(a,b) memset(a,b,sizeof a) 4 #define mp make_pair 5 #define eps 1e-8 6 #define lson l,mid,rt<<1 7 #define rson mid+1,r,rt<<1|1 8 typedef long long LL; 9 typedef unsigned long long ull; 10 const int INF=0x3f3f3f3f; 11 const LL inf=0x3f3f3f3f3f3f3f3fll; 12 int t,n,m,a[51][51],k[50]; 13 LL dp[51][8]; 14 const LL mod=1e9+7; 15 16 LL work(int u,int v,int w) 17 { 18 memset(dp,0,sizeof(dp)); 19 dp[0][0]=1; 20 for(int i=1;i<=m;i++) 21 { 22 int tep=0; 23 for(int j=1;j<=k[i];j++) 24 { 25 if(a[i][j]==u)tep+=1; 26 if(a[i][j]==v)tep+=2; 27 if(a[i][j]==w)tep+=4; 28 } 29 for(int j=0;j<8;j++)dp[i][j]=dp[i-1][j]; 30 for(int j=0;j<8;j++)dp[i][j^tep]+=dp[i-1][j],dp[i][j^tep]%=mod; 31 } 32 return dp[m][7]%mod; 33 } 34 int main() 35 { 36 int T,Case=0; 37 scanf("%d",&T); 38 while(T--) 39 { 40 scanf("%d%d",&n,&m); 41 for(int i=1;i<=m;i++) 42 { 43 scanf("%d",&k[i]); 44 for(int j=1;j<=k[i];j++)scanf("%d",&a[i][j]); 45 } 46 LL ans=0; 47 for(int i=1;i<=n;i++) 48 for(int j=1;j<=n;j++) 49 for(int k=1;k<=n;k++) 50 ans=ans+work(i,j,k),ans%=mod; 51 printf("Case #%d: %lld ",++Case,ans); 52 } 53 return 0; 54 } 55