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- ...
随机推荐
- linux下一步一步安装禅道项目管理工具
linux下一步一步安装禅道项目管理工具 因为禅道官网的安装教程实在是太简陋了,所以记录在此. 1.安装apache服务 archlinux下直接 sudo pacman -S apache ubun ...
- net-snmp-5.7.3配置编译安装
net-snmp-5.7.3配置编译安装 [TOC] 先看一下系统环境 o@o-pc:~/work/_snmp/net-snmp-5.7.3$ uname -a Linux o-pc 3.16.0-3 ...
- 在Coding.net创建项目开发
先在Coding上创建个项目 只要建个项目推送代码余额就会增加,积累码币可以在商城里兑换相应的商品.为了码币,我也应该建个项目搞搞啊- 记录下过程. 先在Coding上创建个项目 现在是这样,我 ...
- 17.4---返回max,不用if
思路:借助max公式就可以了.max(x,y)=0.5*(x+y+|x-y|) 注意:1,结尾要加(int). 答案: max(x,y)=0.5*(x+y+|x-y|)
- 5.2---小数的二进制表示(CC150)
public static String printBin(double num) { StringBuffer str = new StringBuffer(); str.append('0'); ...
- phpcms常用方法简介
function thumb() /** * 生成缩略图函数 * @param $imgurl 图片路径 * @param $width 缩略图宽度 * @param $height 缩略图高度 * ...
- SUSE下FTP服务器搭建
FTP(File Transfer Protocol),是TCP/IP网络上两台计算机传送文件的协议,是在TCP/IP网络和Internet上最早使用的协议之一,属于网络协议组的应 用层.FTP客户机 ...
- form、iframe实现异步上传文件
转载自:http://blog.csdn.net/sunjing21/article/details/4779321 实现主要功能: 页面提供一个上传图片的input file选择框,用于上传某一类型 ...
- 使用WKWebView替换UIWebView
开发App的过程中,常常会遇到在App内部加载网页,通常用UIWebView加载.这个自iOS2开始使用的网页加载器一直是开发的心病:加载速度慢,占用内存多,优化困难.如果加载网页多,还可能因为过量占 ...
- visio 到处流程图
文件 -> 另存为 (选 .jpg) 选自定义,然后 300 * 300 像素.