FZU 1704 Turn off the light

来源:互联网 发布:软件系统设计文档 编辑:程序博客网 时间:2024/06/09 06:19

Problem Description

There are N lights and M switches in Peter’s bedroom. Every switch controls some lights among all. When press the switch, these lights will change their statuses (the lighting ones will be turn off, while the shutting one will be turn on.) Now some lights are lighting. Peter would like to know that under the premises of not pressing one switch twice, how many methods he could turn all the lights off. There is always at least one way to turn all the lights off.

Input

The first line of the input is an integer T which indicates the number of test cases.
For each test case, the first line are two integers N (1 ≤ N ≤ 100) and M (1 ≤ M ≤ 100).
Second line contains N number indicating that the ith light is on if the ith number is 1, or 0 otherwise.
The ith line of the following M lines contains a number D (1 ≤ D ≤ N) and D numbers, indicating the lights under this switch’s control. Lights are numbered from 1 to N.

Output

For each test case, print a line contains the answer.

Sample Input

1
2 3
1 1
2 1 2
1 1
1 2

Sample Output

#include<iostream>#include<cstring>#include<cstdio>using namespace std;int a[110][110],b[100];int main(){int t;scanf("%d",&t);while(t--){int n,m,i,j,k;memset(a,0,sizeof(a));scanf("%d%d",&n,&m);for(i=0;i<n;i++) scanf("%d",&a[i][m]);for(i=0;i<m;i++){int d,x;scanf("%d",&d);while(d--){scanf("%d",&x);a[x-1][i]=1;}}int res=0,r=0;for(i=0;i<m&&r<n;i++){for(j=r;j<n;j++){if(a[j][i]>0){if(j!=r)for(k=i;k<=m;k++) swap(a[j][k],a[r][k]);break;}}if(a[r][i]==0){res++;continue;}for(j=0;j<n;j++){if(j!=r&&a[j][i]!=0){for(k=i;k<=m;k++) a[j][k]^=a[r][k];}}r++;}int len=1,y;b[0]=1;for(i=0;i<m-r;i++){y=0;for(j=0;j<len;j++){b[j]=b[j]*2+y;y=b[j]/10;b[j]%=10;}if(y!=0){b[len]=y;len++;}}for(i=len-1;i>=0;i--) printf("%d",b[i]);printf("\n");}return 0;}


0 0
原创粉丝点击