设为首页 加入收藏

TOP

hdu 3364 Lanterns
2015-07-20 17:43:36 来源: 作者: 【 】 浏览:1
Tags:hdu 3364 Lanterns

Lanterns

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1012 Accepted Submission(s): 405


Problem Description Alice has received a beautiful present from Bob. The present contains n lanterns and m switches. Each switch controls some lanterns and pushing the switch will change the state of all lanterns it controls from off to on or from on to off. A lantern may be controlled by many switches. At the beginning, all the lanterns are off.

Alice wants to change the state of the lanterns to some specific configurations and she knows that pushing a switch more than once is pointless. Help Alice to find out the number of ways she can achieve the goal. Two ways are different if and only if the sets (including the empty set) of the switches been pushed are different.

Input The first line contains an integer T (T<=5) indicating the number of test cases.
The first line of each test case contains an integer n (1<=n<=50) and m (1<=m<=50).
Then m lines follow. Each line contains an integer k (k<=n) indicating the number of lanterns this switch controls.
Then k integers follow between 1 and n inclusive indicating the lantern controlled by this switch.
The next line contains an integer Q (1<=Q<=1000) represent the number of queries of this test case.
Q lines follows. Each line contains n integers and the i-th integer indicating that the state (1 for on and 0 for off) of the i-th lantern of this query.

Output For each test case, print the case number in the first line. Then output one line containing the answer for each query.
Please follow the format of the sample output.
Sample Input
2
3 2
2 1 2
2 1 3
2
0 1 1
1 1 1
3 3
0
0
0
2
0 0 0
1 0 0

Sample Output
Case 1:
1
0
Case 2:
8
0

Source “光庭杯”第五届华中北区程序设计邀请赛 暨 WHU第八届程序设计竞赛

题解及代码:


这道题目其实直接套模版就可以了,但是为了节省时间,我们可以使用高消将这m个同时进行计算就可以了。

#include 
  
   
#include 
   
     #include 
    
      #include 
     
       using namespace std; int a[60][1060],x[1060]; int equ,var,d; void Debug() { for(int i=0;i
      
       a[max_r][col]) max_r=i; if(max_r!=k) for(int i=0;i<=var+d;i++) { swap(a[max_r][i],a[k][i]); } if(a[k][col]==0) { k--; continue; } for(int i=k+1;i
       
        





】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇hdu 4731 Minimum palindrome(构.. 下一篇Leetcode 贪心 Jump Game II

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·C++中智能指针的性能 (2025-12-25 03:49:29)
·如何用智能指针实现c (2025-12-25 03:49:27)
·如何在 C 语言中管理 (2025-12-25 03:20:14)
·C语言和内存管理有什 (2025-12-25 03:20:11)
·为什么C语言从不被淘 (2025-12-25 03:20:08)