除法不能用于同余系,要辗转相除。注意不能加入柱子到矩阵。

#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的房间 (矩阵树,辗转相除高斯消元)的更多相关文章

  1. [HEOI2015]小Z的房间(矩阵树定理学习笔记)

    题目描述 你突然有了一个大房子,房子里面有一些房间.事实上,你的房子可以看做是一个包含n*m个格子的格状矩形,每个格子是一个房间或者是一个柱子.在一开始的时候,相邻的格子之间都有墙隔着. 你想要打通一 ...

  2. 【bzoj4031】[HEOI2015]小Z的房间 矩阵树定理

    题目描述 你突然有了一个大房子,房子里面有一些房间.事实上,你的房子可以看做是一个包含n*m个格子的格状矩形,每个格子是一个房间或者是一个柱子.在一开始的时候,相邻的格子之间都有墙隔着. 你想要打通一 ...

  3. bzoj4031 [HEOI2015]小Z的房间——矩阵树定理

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4031 矩阵树定理的模板题(第一次的矩阵树定理~): 有点细节,放在注释里了. 代码如下: # ...

  4. BZOJ 4031: [HEOI2015]小Z的房间 [矩阵树定理 行列式取模]

    http://www.lydsy.com/JudgeOnline/problem.php?id=4031 裸题........ 问题在于模数是$10^9$ 我们发现消元的目的是让一个地方为0 辗转相除 ...

  5. BZOJ 4031: [HEOI2015]小Z的房间 (矩阵树定理 板题)

    背结论 : 度-邻 CODE1 O(n3logn)O(n^3logn)O(n3logn) #include <bits/stdc++.h> using namespace std; typ ...

  6. [HEOI2015] 小Z的房间 - 矩阵树定理

    #include <bits/stdc++.h> using namespace std; #define int long long const int N = 105; const i ...

  7. bzoj 4031: 小Z的房间 矩阵树定理

    bzoj 4031: 小Z的房间 矩阵树定理 题目: 你突然有了一个大房子,房子里面有一些房间.事实上,你的房子可以看做是一个包含n*m个格子的格状矩形,每个格子是一个房间或者是一个柱子.在一开始的时 ...

  8. LG4111/LOJ2122 「HEOI2015」小Z的房间 矩阵树定理

    问题描述 LG4111 题解 矩阵树定理板子题. \(\mathrm{Code}\) #include<bits/stdc++.h> using namespace std; #defin ...

  9. BZOJ 2467: [中山市选2010]生成树(矩阵树定理+取模高斯消元)

    http://www.lydsy.com/JudgeOnline/problem.php?id=2467 题意: 思路:要用矩阵树定理不难,但是这里的话需要取模,所以是需要计算逆元的,但是用辗转相减会 ...

随机推荐

  1. Typora详细教程以及下载

    ​ 发现一篇非常不错的 Typora 教程,分享给大家. 原文链接:https://www.cnblogs.com/hyacinthLJP/p/16123932.html 作者:MElephant T ...

  2. 前端获取cookie,并解析cookie成JSON对象

    getCookie() { let strcookie = document.cookie; //获取cookie字符串 let arrcookie = strcookie.split("; ...

  3. vue大型电商项目尚品汇(前台篇)day05

    紧急更新第二弹,然后就剩下最后一弹,也就是整个前台的项目 一.购物车 1.加入购物车(新知识点) 加入到购物车是需要接口操作的,因为我们需要将用户的加入到购物车的保存到服务器数据库,你的账号后面才会在 ...

  4. Camunda定时器事件示例Demo(Timer Events)

    ​Camunda定时器事件(Timer Events)是由定义的计时器触发的事件.它们可以用作启动事件.中间事件或边界事件.边界事件可以中断,也可以不中断. Camunda定时器事件包括:Timer ...

  5. dotnet 在 linux 上构建问题(RID 的问题)

    个人理解 一方面 /etc/os-release 中定义的的 ID VERSION_ID 是会与源代码中定义 RID 的相对应,如果不对应,就会报错 The specified RuntimeIden ...

  6. 论文解读(USIB)《Towards Explanation for Unsupervised Graph-Level Representation Learning》

    论文信息 论文标题:Towards Explanation for Unsupervised Graph-Level Representation Learning论文作者:Qinghua Zheng ...

  7. BUUCTF-snake

    snake 这是我最想吐槽的一个题目,搞这个蛇在这里.我看的这个图就头皮发麻. 最不愿意做的题,建议以后出题能不能搞个正常的啊. 16进制打开发现压缩包,binwalk提取,得到三个文件 key中是b ...

  8. SAP -熟练使用T-Code SHD0

    SHD0 业务顾问和开发顾问都非常熟悉的一个T-Code, 如果能合理使用它,可以省去许多增强和程序修改工作. 当我需要时,我在这里找不到任何相关文档,这就是为什么我想借此机会向我们自己的SCN提供内 ...

  9. Vue 安装 vue的基本使用 vue的初步使用步骤

    1. 资源: https://cn.vuejs.org/v2/guide/#%E8%B5%B7%E6%AD%A5 进入官网学习 2. 点击安装,要把vue下载到本地文件的根目录中,不要选择压缩版的,这 ...

  10. HTML\Flex tips

    相关文档 HTML:https://www.w3school.com.cn/html/index.asp bootstrap-css: https://v3.bootcss.com/css/#form ...