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 题意: 思路:要用矩阵树定理不难,但是这里的话需要取模,所以是需要计算逆元的,但是用辗转相减会 ...
随机推荐
- 使用 awk 命令统计文本
2022-04-19 11:25:15.008,b4d13bfca8fe4b93a85e65a88520d945,LogScheduler#printLog,10ms,Y,xxxxxxxx 2022- ...
- SeataAT模式原理
Seata架构 Seata将分布式事务理解为一个全局事务,它由若干个分支事务组成,一个分支事务就是一个满足ACID的本地事务. Seata架构中有三个角色: TC (Transaction Coord ...
- [KDTree]数列
NKOJ传送门 describtion 给你一个序列,每个序列有编号(它本身的位置),标识符,数值. 有4种操作 op=0:l,r,x,y将编号在[l,r]的数值x+y op=1:l,r,x,y将标识 ...
- ex_Lucas定理
Lucas定理(p为质数): \(C_n^m=C_{n/p}^{m/p}*C_{n\ mod\ p}^{m\ mod\ p}\) 可是p不为质数怎么办呢? ex_Lucas定理 (p不为质数) 思路 ...
- C++ 获取指定的重载函数地址
刚刚看到一篇博客,说 std::bind 无法绑定正确的重载函数.这里的问题并不是 std::bind 能力不足,而是将函数名传递给 std::bind 时编译器无法取到这个函数的地址(也就是符号,编 ...
- QQ空间未授权评论_已忽略
看群友们聊天时发现的, 大概是做了查看了动态访问时间的一个设置, 但是仅自己可见的说说还是被评论了的这么一个问题. 闲的没事就翻了一下找一下问题. 这个方法嘎嘎鸡肋, 可以说完全没用, 交到tsrc, ...
- 【Redis】事件驱动框架源码分析(多线程)
IO线程初始化 Redis在6.0版本中引入了多线程,提高IO请求处理效率. 在Redis Server启动函数main(server.c文件)中初始化服务之后,又调用了InitServerLast函 ...
- iNeuOS工业互联网操作系统,增加搜索应用、多数据源绑定、视图背景设置颜色、多级别文件夹、组合及拆分图元
目 录 1. 概述... 2 2. 搜索应用... 2 3. 多数据源绑定... 3 4. 视图背景设置颜色... 4 5. 多级别文件夹 ...
- 14.Nginx搭建及优化
Nginx搭建及优化 目录 Nginx搭建及优化 Nginx服务基础 概述 Nginx和Apache的优缺点比较 编译安装Nginx服务 添加Nginx系统服务 Nginx服务配置文件 nginx服务 ...
- SAP string 转 number 类型
try. cl_fdt_calculation=>convert_string_to_number( exporting iv_text = conv #( lwa_at ...