HDU 3364 Lanterns 高斯消元
Lanterns
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.
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.
Please follow the format of the sample output.
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
1
0
Case 2:
8
0
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
#define pii pair<int,int>
#define MP make_pair
typedef long long LL;
const long long INF = 1e18;
const double Pi = acos(-1.0);
, M = 1e6, mod = 1e9+, inf = 2e9;
,c[N][N];
int Guass(int n,int m) {
int i, j;
, j = ; i < n && j < m; ) {
;
for(int k = i; k < n; ++k) {
if(a[k][j]) {
x = k;
break;
}
}) {
++j;
continue;
}
; k <= m; ++k) swap(a[i][k],a[x][k]);
; u < n; ++u) {
if(a[u][j]) {
; k <= m; ++k) {
a[u][k] ^= a[i][k];
}
}
}
++i;
++j;
}
; i < n; ++i) {
if(a[i][m]) {
;
; j < m; ++j) {
;
}
;
}
}
return (m - i);
}
int main() {
int T,n,m,k,x;
scanf("%d",&T);
while(T--) {
scanf("%d%d",&n,&m);
memset(c,,sizeof(c));
; i < m; ++i) {
scanf("%d",&k);
while(k--) {
scanf("%d",&x);
c[x-][i] = ;
}
}
int q;
scanf("%d",&q);
printf("Case %d:\n",cas++);
while(q--) {
; i < n; ++i); j <= m; ++j) a[i][j] = c[i][j];
; i < n; ++i) scanf("%d",&a[i][m]);
LL ans = Guass(n,m);
printf(? :1LL<<ans);
}
}
;
}
HDU 3364 Lanterns 高斯消元的更多相关文章
- HDU 3949 XOR 高斯消元
题目大意:给定一个数组,求这些数组通过异或能得到的数中的第k小是多少 首先高斯消元求出线性基,然后将k依照二进制拆分就可以 注意当高斯消元结束后若末尾有0则第1小是0 特判一下然后k-- 然后HDU输 ...
- hdu 5755(高斯消元——模线性方程组模板)
PS. 看了大神的题解,发现确实可以用m个未知数的高斯消元做.因为确定了第一行的情况,之后所有行的情况都可以根据第一行推. 这样复杂度直接变成O(m*m*m) 知道了是高斯消元后,其实只要稍加处理,就 ...
- HDU 3949 XOR [高斯消元XOR 线性基]
3949冰上走 题意: 给你 N个数,从中取出若干个进行异或运算 , 求最后所有可以得到的异或结果中的第k小值 N个数高斯消元求出线性基后,设秩为$r$,那么总共可以组成$2^r$中数字(本题不能不选 ...
- Time travel HDU - 4418(高斯消元)
Agent K is one of the greatest agents in a secret organization called Men in Black. Once he needs to ...
- hdu 4870 rating(高斯消元求期望)
Rating Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- hdu 6465 线性变换高斯消元
http://acm.hdu.edu.cn/showproblem.php?pid=6465 题意 给你三个点,再给你经过线性变换后的三个点,然后q次询问,给你一个点,需要你输出线性变换后的点 题解 ...
- HDU 3915 Game (高斯消元)
题意:有n堆石子,每个人只能从某一堆至少拿走一个,不能拿者败.问事先拿走某些堆的石子,使得先手必败. 析:将石子拆成二进制,未知数为1表示保留该堆石子,为0表示事先拿走该堆石子.最后求自由变元的数目, ...
- HDU 3364 Lanterns (高斯消元)
题意:有n个灯和m个开关,每个开关控制数个灯的状态改变,给出k条询问,问使灯的状态变为询问中的状态有多少种发法. 析:同余高斯消元法,模板题,将每个开关控制每个灯列成行列式,最终状态是结果列,同余高斯 ...
- HDU 4870 Rating(高斯消元 )
HDU 4870 Rating 这是前几天多校的题目,高了好久突然听旁边的大神推出来说是可以用高斯消元,一直喊着赶快敲模板,对于从来没有接触过高斯消元的我来说根本就是一头雾水,无赖之下这几天做DP ...
随机推荐
- XsltListViewWebPart 和自定义列表视图
http://msdn.microsoft.com/zh-cn/library/ff806162(v=office.14).aspx
- java访问数据库的sql
drop database if exists STOREDB;create database STOREDB;use STOREDB; create table CUSTOMERS ( ID big ...
- delphi XE5下安卓开发技巧
delphi XE5下安卓开发技巧 一.手机快捷方式显示中文名称 project->options->Version Info-label(改成需要显示的中文名即可),但是需要安装到安卓手 ...
- ACM/ICPC 之 数论-斐波拉契●卢卡斯数列(HNNUOJ 11589)
看到这个标题,貌似很高大上的样子= =,其实这个也是大家熟悉的东西,先给大家科普一下斐波拉契数列. 斐波拉契数列 又称黄金分割数列,指的是这样一个数列:0.1.1.2.3.5.8.13.21.34.… ...
- 3.SpringMVC修改配置文件路径和给界面传递数据
1.修改配置文件路径 达到 配置多文件的目的 web.xml文件中基础配置有springMVC配置的servlet路径 <servlet-name>SpringMVC</serv ...
- 实现Windows Phone 8中ListBox的分页加载
功能就是ListBox滚动到最下方的时候,能够自动加载下一页的内容. 解决问题的关键就是如何判断ListBox已经加载到了最底部. 网上找了两个解决方法: 1 http://googlers.itey ...
- Android实现Banner界面广告图片循环轮播(包括实现手动滑动循环)
前言:经常会看到有一些app的banner界面可以实现循环播放多个广告图片和手动滑动循环.本以为单纯的ViewPager就可以实现这些功能.但是蛋疼的事情来了,ViewPager并不支持循环翻页.所以 ...
- java常用工具类(java技术交流群57388149)
package com.itjh.javaUtil; import java.util.ArrayList; import java.util.List; /** * * String工具类. ...
- 火狐----此地址使用了一个通常用于网络浏览以外的端口。出于安全原因,Firefox 取消了该请求。
FirFox打开80以外的端口,会弹出以下提示: “此地址使用了一个通常用于网络浏览以外的端口.出于安全原因,Firefox 取消了该请求.”.经网上搜索,解决方法如下: 在Firefox地址栏输入a ...
- HTML标记语法之表格元素
语法与语义: <table>和</table>定义表格的开始和结束 <thead>和</thead>定义表格头部的开始和结束 <tbody> ...