Lanterns


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
 
题意:
  n个灯,m个开关
  给你每个开关可以控制哪些灯
  q个询问
  每次询问你从权灭状态 到 当前n个灯的状态 的方案数
题解:
  每次都求一遍Guass
  

  1. #include<iostream>
  2. #include<algorithm>
  3. #include<cstdio>
  4. #include<cstring>
  5. #include<cmath>
  6. #include<vector>
  7. using namespace std;
  8. #pragma comment(linker, "/STACK:102400000,102400000")
  9. #define ls i<<1
  10. #define rs ls | 1
  11. #define mid ((ll+rr)>>1)
  12. #define pii pair<int,int>
  13. #define MP make_pair
  14. typedef long long LL;
  15. const long long INF = 1e18;
  16. const double Pi = acos(-1.0);
  17. , M = 1e6, mod = 1e9+, inf = 2e9;
  18.  
  19. ,c[N][N];
  20. int Guass(int n,int m) {
  21. int i, j;
  22. , j = ; i < n && j < m; ) {
  23. ;
  24. for(int k = i; k < n; ++k) {
  25. if(a[k][j]) {
  26. x = k;
  27. break;
  28. }
  29. }) {
  30. ++j;
  31. continue;
  32. }
  33. ; k <= m; ++k) swap(a[i][k],a[x][k]);
  34. ; u < n; ++u) {
  35. if(a[u][j]) {
  36. ; k <= m; ++k) {
  37. a[u][k] ^= a[i][k];
  38. }
  39. }
  40. }
  41. ++i;
  42. ++j;
  43. }
  44. ; i < n; ++i) {
  45. if(a[i][m]) {
  46. ;
  47. ; j < m; ++j) {
  48. ;
  49. }
  50. ;
  51. }
  52. }
  53. return (m - i);
  54. }
  55. int main() {
  56. int T,n,m,k,x;
  57. scanf("%d",&T);
  58. while(T--) {
  59. scanf("%d%d",&n,&m);
  60. memset(c,,sizeof(c));
  61. ; i < m; ++i) {
  62. scanf("%d",&k);
  63. while(k--) {
  64. scanf("%d",&x);
  65. c[x-][i] = ;
  66. }
  67. }
  68. int q;
  69. scanf("%d",&q);
  70. printf("Case %d:\n",cas++);
  71. while(q--) {
  72. ; i < n; ++i); j <= m; ++j) a[i][j] = c[i][j];
  73. ; i < n; ++i) scanf("%d",&a[i][m]);
  74. LL ans = Guass(n,m);
  75. printf(? :1LL<<ans);
  76. }
  77. }
  78. ;
  79. }

HDU 3364 Lanterns 高斯消元的更多相关文章

  1. HDU 3949 XOR 高斯消元

    题目大意:给定一个数组,求这些数组通过异或能得到的数中的第k小是多少 首先高斯消元求出线性基,然后将k依照二进制拆分就可以 注意当高斯消元结束后若末尾有0则第1小是0 特判一下然后k-- 然后HDU输 ...

  2. hdu 5755(高斯消元——模线性方程组模板)

    PS. 看了大神的题解,发现确实可以用m个未知数的高斯消元做.因为确定了第一行的情况,之后所有行的情况都可以根据第一行推. 这样复杂度直接变成O(m*m*m) 知道了是高斯消元后,其实只要稍加处理,就 ...

  3. HDU 3949 XOR [高斯消元XOR 线性基]

    3949冰上走 题意: 给你 N个数,从中取出若干个进行异或运算 , 求最后所有可以得到的异或结果中的第k小值 N个数高斯消元求出线性基后,设秩为$r$,那么总共可以组成$2^r$中数字(本题不能不选 ...

  4. Time travel HDU - 4418(高斯消元)

    Agent K is one of the greatest agents in a secret organization called Men in Black. Once he needs to ...

  5. hdu 4870 rating(高斯消元求期望)

    Rating Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  6. hdu 6465 线性变换高斯消元

    http://acm.hdu.edu.cn/showproblem.php?pid=6465 题意 给你三个点,再给你经过线性变换后的三个点,然后q次询问,给你一个点,需要你输出线性变换后的点 题解 ...

  7. HDU 3915 Game (高斯消元)

    题意:有n堆石子,每个人只能从某一堆至少拿走一个,不能拿者败.问事先拿走某些堆的石子,使得先手必败. 析:将石子拆成二进制,未知数为1表示保留该堆石子,为0表示事先拿走该堆石子.最后求自由变元的数目, ...

  8. HDU 3364 Lanterns (高斯消元)

    题意:有n个灯和m个开关,每个开关控制数个灯的状态改变,给出k条询问,问使灯的状态变为询问中的状态有多少种发法. 析:同余高斯消元法,模板题,将每个开关控制每个灯列成行列式,最终状态是结果列,同余高斯 ...

  9. HDU 4870 Rating(高斯消元 )

    HDU 4870   Rating 这是前几天多校的题目,高了好久突然听旁边的大神推出来说是可以用高斯消元,一直喊着赶快敲模板,对于从来没有接触过高斯消元的我来说根本就是一头雾水,无赖之下这几天做DP ...

随机推荐

  1. ios 在中国地区,24小时时间格式 系统设定下 获得12小时制时间的方法

    如题,在中国地区,24小时时间格式 系统设定下,如果单单使用 NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 之后,无论用hh ...

  2. c++ 文件utf-8格式

    #include <stdio.h> int i = 0; while (i < 20) {    i++;    WriteLog("d:\\log.txt", ...

  3. Collection、Map、数组 遍历方式

    结论:无论是数组还是Collection for each 都是一个非常好的选择 一.for each底层实现 对于Collection,for each是隐式调用Iterator实现的,效率比显示调 ...

  4. 关于CentOS普通用户无法登录SSH问题

    在CentOS中,假若一切都顺利的话,你建新一个用户,它就自动添加到SSHD登录服务中的处的了,不必手动或再设置什么,但有些情况下,我们的系统只允许root用户登录,那么,我们就要进行一些必要的设置, ...

  5. codeforces 493A. Vasya and Football 解题报告

    题目链接:http://codeforces.com/contest/493/problem/A 题目意思:给出两个字符串,分别代表 home 和 away.然后有 t 个player,每个playe ...

  6. [Android Rro] SDK JAR

    cd ../../../outputs/aar/mkdir AAR_VERSIONmkdir JAR_VERSIONmv app-release.aar AAR_VERSION/${project_n ...

  7. 多线程编程4 - NSOperationQueue

    一.简介 一个NSOperation对象可以通过调用start方法来执行任务,默认是同步执行的.也可以将NSOperation添加到一个NSOperationQueue(操作队列)中去执行,而且是异步 ...

  8. apache ab下载测试

    http://httpd.apache.org/docs/2.0/programs/ab.html-->http://httpd.apache.org/docs/current/platform ...

  9. VAssistX的VA Snippet Editor的类注释和函数注释

    title:类注释shortcut:=== /******************************************************** [DateTime]:$YEAR$.$M ...

  10. Android Service 与 Thread 的区别

    Ref:http://blog.csdn.net/jiangwei0910410003/article/details/17008687 1). Thread:Thread 是程序执行的最小单元,它是 ...