Luogu4111 [HEOI2015]小Z的房间 (矩阵树,辗转相除高斯消元)
除法不能用于同余系,要辗转相除。注意不能加入柱子到矩阵。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int a = (b); a <= (c); ++ a)
#define nR(a,b,c) for(register int a = (b); a >= (c); -- a)
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Abs(a) ((a) < 0 ? -(a) : (a))
#define Swap(a,b) a^=b^=a^=b
#define ll long long
#define ON_DEBUG
#ifdef ON_DEBUG
#define D_e_Line printf("\n\n----------\n\n")
#define D_e(x) cout << #x << " = " << x << endl
#define Pause() system("pause")
#define FileOpen() freopen("in.txt","r",stdin);
#else
#define D_e_Line ;
#define D_e(x) ;
#define Pause() ;
#define FileOpen() ;
#endif
struct ios{
template<typename ATP>ios& operator >> (ATP &x){
x = 0; int f = 1; char c;
for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;
while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
x*= f;
return *this;
}
}io;
using namespace std;
const int N = 107;
const int mod = 1000000000;
int n, m;
int a[N][N];
//inline void Gauss(int n){
// R(i,1,n){
// int r = i;
// R(j,i + 1,n){
// if(Abs(a[r][i]) > Abs(a[i][i])){
// r = i;
// }
// }
// if(a[r][i] == 0){
// printf("0");
// return;
// }
// swap(a[r], a[i]);
// R(j,i + 1,n){
// int t = a[j][i] / a[i][i];
// R(k,1,n){
// a[j][k] -= t * a[i][k];
// }
// }
// }
// long long ans = 1;
// R(i,1,n) ans = 1ll * ans * a[i][i] % mod;
// printf("%lld", ans);
//}
inline void Gauss(int n){
int ans = 1;
R(i,1,n){
R(j,i + 1,n){
while(a[j][i]){
int t = a[i][i] / a[j][i];
R(k,1,n){
a[i][k] = (a[i][k] - 1ll * t * a[j][k] % mod + mod) % mod;
}
swap(a[i], a[j]);
ans = -ans;
}
}
ans = (1ll * ans * a[i][i] % mod + mod) % mod;
}
printf("%d", ans);
}
int mp[N][N], mpIndex;
char str[N][N];
inline void add(int x, int y){
++a[x][x];
++a[y][y];
--a[x][y];
--a[y][x];
}
int main(){
io >> n >> m;
R(i,1,n){
scanf("%s", str[i] + 1);
}
R(i,1,n){
R(j,1,m){
if(str[i][j] == '.'){
mp[i][j] = ++mpIndex;
}
}
}
R(i,1,n){
R(j,1,m){
if(str[i][j] == '.'){
if(str[i - 1][j] == '.'){
add(mp[i][j], mp[i - 1][j]);
}
if(str[i][j - 1] == '.'){
add(mp[i][j], mp[i][j - 1]);
}
}
}
}
Gauss(mpIndex - 1);
return 0;
}

Luogu4111 [HEOI2015]小Z的房间 (矩阵树,辗转相除高斯消元)的更多相关文章
- [HEOI2015]小Z的房间(矩阵树定理学习笔记)
题目描述 你突然有了一个大房子,房子里面有一些房间.事实上,你的房子可以看做是一个包含n*m个格子的格状矩形,每个格子是一个房间或者是一个柱子.在一开始的时候,相邻的格子之间都有墙隔着. 你想要打通一 ...
- 【bzoj4031】[HEOI2015]小Z的房间 矩阵树定理
题目描述 你突然有了一个大房子,房子里面有一些房间.事实上,你的房子可以看做是一个包含n*m个格子的格状矩形,每个格子是一个房间或者是一个柱子.在一开始的时候,相邻的格子之间都有墙隔着. 你想要打通一 ...
- bzoj4031 [HEOI2015]小Z的房间——矩阵树定理
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4031 矩阵树定理的模板题(第一次的矩阵树定理~): 有点细节,放在注释里了. 代码如下: # ...
- BZOJ 4031: [HEOI2015]小Z的房间 [矩阵树定理 行列式取模]
http://www.lydsy.com/JudgeOnline/problem.php?id=4031 裸题........ 问题在于模数是$10^9$ 我们发现消元的目的是让一个地方为0 辗转相除 ...
- BZOJ 4031: [HEOI2015]小Z的房间 (矩阵树定理 板题)
背结论 : 度-邻 CODE1 O(n3logn)O(n^3logn)O(n3logn) #include <bits/stdc++.h> using namespace std; typ ...
- [HEOI2015] 小Z的房间 - 矩阵树定理
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 105; const i ...
- bzoj 4031: 小Z的房间 矩阵树定理
bzoj 4031: 小Z的房间 矩阵树定理 题目: 你突然有了一个大房子,房子里面有一些房间.事实上,你的房子可以看做是一个包含n*m个格子的格状矩形,每个格子是一个房间或者是一个柱子.在一开始的时 ...
- LG4111/LOJ2122 「HEOI2015」小Z的房间 矩阵树定理
问题描述 LG4111 题解 矩阵树定理板子题. \(\mathrm{Code}\) #include<bits/stdc++.h> using namespace std; #defin ...
- BZOJ 2467: [中山市选2010]生成树(矩阵树定理+取模高斯消元)
http://www.lydsy.com/JudgeOnline/problem.php?id=2467 题意: 思路:要用矩阵树定理不难,但是这里的话需要取模,所以是需要计算逆元的,但是用辗转相减会 ...
随机推荐
- Vue关闭语法检测
为什么?为了防止写到一半保存,报错.关闭默认的语法检测 新建vue.config.js 1.vue.config.js的作用是允许你修改脚手架中wekpack的默认参数. 2.vue.config.j ...
- uniapp设置竖屏
//在APP.vue中的onLaunch钩子写入plus.screen.lockOrientation('portrait-primary');
- MUI+html5+javascript 点击事件触发页面间传值
关于如何进行页面转跳,请看 https://www.cnblogs.com/JUNELITTLEPANDA/p/15956176.html,以下跳转方法是采用的其中一种 1- 仅适用于移动端,pc端 ...
- Asp.Net Core Identity 多数据库支持
Asp.Net Core Identity 是.Net自带的身份认证系统,支持用户界面 (UI) 登录功能,并且管理用户.密码.配置文件数据.角色.声明.令牌.电子邮件确认等等.使用Visual St ...
- 大数据分析VMWare虚拟机centos系统下配置网络参数
最近搞大数据方面的数据,通过网上视频学习和自己实践,有些不成文的实践就零碎的记录在此吧. 系统也可安装CentOS DVD版. 1.先进入配置文件,并查看基本情况,如下: 2.用vi编辑器打开物理网卡 ...
- D3.JS结合Canvas实现直方图,散点图,等高线图,密度图
接触到D3.JS,感觉在图表方面实现的很好,于是深入了解了一下,想在项目中使用, 可是当看到DEMO时才发现,基本上所有的DEMO都是基于SVG,虽然D3.JS声称支持CANVAS,可并没有发现一例使 ...
- [pwn基础]Pwntools学习
目录 [pwn基础]Pwntools学习 Pwntools介绍 Pwntools安装 Pwntools常用模块和函数 pwnlib.tubes模块学习 tubes.process pwnlib.con ...
- 【python基础】第05回 数据类型,交互,格式化输出,运算符
上节内容回顾 1.python的注释 # 单行注释 pycharm快捷键:ctrl+? '''多行注释''' """多行注释""" 2.py ...
- 原生实现.NET5.0+ 自定义日志
一.定义一个静态类 声明一个 ReaderWriterLockSlim 对象 用于并发控制 1 /// <summary> 2 /// IO锁 3 /// </summary> ...
- NC13328 倒水
NC13328 倒水 题目 题目描述 有一个大水缸,里面水的温度为 \(T\) 单位,体积为 \(C\) 升.另有 \(n\) 杯水(假设每个杯子的容量是无限的),每杯水的温度为 \(t[i]\) 单 ...