HDU3364 Lanterns(求矩阵的秩)
求矩阵的秩,及判断有无解
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
using namespace std;
typedef long long LL;
const int N = 60, INF = 0x3F3F3F3F;
const double eps = 1e-8;
template<typename T>
int gauss_jordan(T A[N][N], int n, int m){
int i, c;
for(i = 0, c = 0; i < n && c < m; i++, c++){
int r = i;
for(int j = i + 1; j < n; j++){
if(A[j][c]){
r = j;
break;
}
}
if(A[r][c] == 0){
i--;
continue;
}
if(r != i){
for(int j = 0; j <= m; j++){
swap(A[r][j], A[i][j]);
}
}
for(int k = 0; k < n; k++){
if(k != i && A[k][c]){
for(int j = m; j >= c; j--){
A[k][j] ^= A[i][j];
}
}
}
}
for(int j = i ; j < n; j++){
if(A[j][m]){
return -1;
}
}
return i;
}
int a[N][N], b[N][N];
int main(){
int t;
cin>>t;
for(int cas = 1; cas <= t; cas++){
int n, m;
scanf("%d %d", &n, &m);
memset(b, 0, sizeof(b));
for(int i = 0; i < m; i++){
int cnt;
scanf("%d", &cnt);
while(cnt--){
int v;
scanf("%d", &v);
v--;
b[v][i] = 1;
}
}
int q;
scanf("%d", &q);
printf("Case %d:\n", cas);
while(q--){
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
a[i][j] = b[i][j];
}
}
for(int i = 0; i < n; i++){
scanf("%d", &a[i][m]);
}
int ans = gauss_jordan(a, n, m);
if(ans == -1){
printf("0\n");
}else{
printf("%I64d\n", 1ll << (m - ans));
}
}
}
return 0;
}
HDU3364 Lanterns(求矩阵的秩)的更多相关文章
- Light OJ 1288 Subsets Forming Perfect Squares 高斯消元求矩阵的秩
题目来源:Light OJ 1288 Subsets Forming Perfect Squares 题意:给你n个数 选出一些数 他们的乘积是全然平方数 求有多少种方案 思路:每一个数分解因子 每隔 ...
- POJ 开关问题 1830【高斯消元求矩阵的秩】
Language: Default 开关问题 Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6656 Accepted: ...
- paper 127:机器学习中的范数规则化之(二)核范数与规则项参数选择
机器学习中的范数规则化之(二)核范数与规则项参数选择 zouxy09@qq.com http://blog.csdn.net/zouxy09 上一篇博文,我们聊到了L0,L1和L2范数,这篇我们絮叨絮 ...
- Breeze库API总结(Spark线性代数库)(转载)
导入 import breeze.linalg._ import breeze.numerics._ Spark Mllib底层的向量.矩阵运算使用了Breeze库,Breeze库提供了Vector/ ...
- 给深度学习入门者的Python快速教程 - numpy和Matplotlib篇
始终无法有效把word排版好的粘贴过来,排版更佳版本请见知乎文章: https://zhuanlan.zhihu.com/p/24309547 实在搞不定博客园的排版,排版更佳的版本在: 给深度学习入 ...
- UVA11542 Square(高斯消元 异或方程组)
建立方程组消元,结果为2 ^(自由变元的个数) - 1 采用高斯消元求矩阵的秩 方法一: #include<cstdio> #include<iostream> #includ ...
- L0、L1与L2范数、核范数(转)
L0.L1与L2范数.核范数 今天我们聊聊机器学习中出现的非常频繁的问题:过拟合与规则化.我们先简单的来理解下常用的L0.L1.L2和核范数规则化.最后聊下规则化项参数的选择问题.这里因为篇幅比较庞大 ...
- Matlab - 线性方程组求解
常用函数:det 计算矩阵的行列式的值inv 求矩阵的逆阵rank 求矩阵的秩[V D]=eig(A) 求矩阵A的特征值和特征向量poly 求矩阵的特征多项式rref 用初等变换将矩阵化成行阶梯形nu ...
- 高斯消元 & 线性基【学习笔记】
高斯消元 & 线性基 本来说不写了,但还是写点吧 [update 2017-02-18]现在发现真的有好多需要思考的地方,网上很多代码感觉都是错误的,虽然题目通过了 [update 2017- ...
随机推荐
- Java 日期加减计算.
1.用Java.util.Calender来实现 Calendar calendar=Calendar.getInstance(); calendar.setTime(new Date()) ...
- 应用HTK搭建语音拨号系统2:创建单音素HMM模型
选自:http://maotong.blog.hexun.com/6204849_d.html 苏统华 哈尔滨工业大学人工智能研究室 2006年10月30日 声明:版权所有,转载请注明作者和来源 该系 ...
- 一个简单的log
#pragma once #include <windows.h> #include <process.h> class CLogger { public: static CR ...
- Git索引
原文: http://gitbook.liuhui998.com/7_4.html git中的索引(index)是一个存放了排好序的路径的二进制文件(通常是.git/index), 每一个条目都附带有 ...
- git stash简介
原文:http://gitbook.liuhui998.com/4_5.html 一.基本操作 当你正在做一项复杂的工作时, 发现了一个和当前工作不相关但是又很讨厌的bug. 你这时想先修复bug再做 ...
- .net MVC借助Iframe实现无刷新上传文件
html: <div id="uploadwindow" style="display: none;"> <form action=" ...
- C#系统委托之Action And Func
Action Action<T> Func Func<T> Action:封装一个方法,该方法不具有参数并且不返回值 public delegate void Action() ...
- Pywinauto在Windows Twain Driver自动化测试中的应用研究
摘 要: 以Python为基础,结合对Twain Driver测试工具的具体需求,将Pywinauto引入到Twain Driver的自动化测试中.介绍了Pywinauto的基本概念,通过测试用例说 ...
- jquery checkbox 复选框多次点击判断选中状态,以及全选/取消的代码示例
2015年12月21日 10:52:51 星期一 目标, 点击当前的checbox, 判断点击后当前checkbox是否是选中状态. html: <input type="checkb ...
- ABAP 将SAP用户ID转换成用户名
FORM frm_coverted_name USING usrid TYPE sy-uname CHANGING name TYPE adrp-name ...