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

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 105;
const int mod = 1e+9;
namespace mat {
int a[N][N];
int n,p=1;
int Gauss() {
    int ans = 1;
    for(int i = 1; i < n; i ++) {
        for(int j = i + 1; j < n; j ++)
            while(a[j][i]) {
                int t = a[i][i] / a[j][i];
                for(int k = i; k < n; k ++)
                    a[i][k] = (a[i][k] - t * a[j][k] + mod) % mod;
                swap(a[i], a[j]);
                ans = - ans;
            }
        ans = (ans * a[i][i]) % mod;
    }
    return (ans + mod) % mod;
}
} // namespace mat
int a[N][N],d[N][N],b[N][N],c[N][N],n,m,ind;
char str[N];
int id(int i,int j) {
    return c[i][j];
}
int add(int p,int q) {
    a[p][q]=a[q][p]=1;
    d[p][p]++;
    d[q][q]++;
}
signed main() {
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i=1; i<=n; i++) {
        cin>>str+1;
        for(int j=1; j<=m; j++) {
            if(str[j]=='.') b[i][j]=0, c[i][j]=++ind;
            else b[i][j]=1;
        }
    }
    for(int i=1; i<=n; i++) {
        for(int j=1; j<=m; j++) {
            if(b[i][j]==0) {
                if(i<n && b[i+1][j]==0) add(id(i,j),id(i+1,j));
                if(j<m && b[i][j+1]==0) add(id(i,j),id(i,j+1));
            }
        }
    }
    mat::n=ind;
    for(int i=1; i<=ind; i++) {
        for(int j=1; j<=ind; j++) {
            mat::a[i][j]=d[i][j]-a[i][j];
        }
    }
    cout<<mat::Gauss()<<endl;
}
												
											[HEOI2015] 小Z的房间 - 矩阵树定理的更多相关文章
- 【bzoj4031】[HEOI2015]小Z的房间  矩阵树定理
		
题目描述 你突然有了一个大房子,房子里面有一些房间.事实上,你的房子可以看做是一个包含n*m个格子的格状矩形,每个格子是一个房间或者是一个柱子.在一开始的时候,相邻的格子之间都有墙隔着. 你想要打通一 ...
 - bzoj4031 [HEOI2015]小Z的房间——矩阵树定理
		
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4031 矩阵树定理的模板题(第一次的矩阵树定理~): 有点细节,放在注释里了. 代码如下: # ...
 - [HEOI2015]小Z的房间(矩阵树定理学习笔记)
		
题目描述 你突然有了一个大房子,房子里面有一些房间.事实上,你的房子可以看做是一个包含n*m个格子的格状矩形,每个格子是一个房间或者是一个柱子.在一开始的时候,相邻的格子之间都有墙隔着. 你想要打通一 ...
 - 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 ...
 - bzoj 4031: 小Z的房间 矩阵树定理
		
bzoj 4031: 小Z的房间 矩阵树定理 题目: 你突然有了一个大房子,房子里面有一些房间.事实上,你的房子可以看做是一个包含n*m个格子的格状矩形,每个格子是一个房间或者是一个柱子.在一开始的时 ...
 - LG4111/LOJ2122 「HEOI2015」小Z的房间  矩阵树定理
		
问题描述 LG4111 题解 矩阵树定理板子题. \(\mathrm{Code}\) #include<bits/stdc++.h> using namespace std; #defin ...
 - BZOJ.4031.[HEOI2015]小Z的房间(Matrix Tree定理 辗转相除)
		
题目链接 辗转相除解行列式的具体实现? 行列式的基本性质. //864kb 64ms //裸的Matrix Tree定理.练习一下用辗转相除解行列式.(因为模数不是质数,所以不能直接乘逆元来高斯消元. ...
 - BZOJ 4031 [HEOI2015]小Z的房间(Matrix-Tree定理)
		
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=4031 [题目大意] 你突然有了一个大房子,房子里面有一些房间. 事实上,你的房子可以看 ...
 
随机推荐
- css基础-float浮动
			
float实现文字环绕图片效果: <!DOCTYPE html> <html lang="en"> <head> <meta charse ...
 - Spring Mvc Http 400 Bad Request问题排查
			
如果遇到了Spring MVC报错400,而且没有返回任何信息的情况下该如何排查问题? 问题描述 一直都没毛病的接口,今天测试的时候突然报错400 Bad Request,而且Response没有返回 ...
 - scrapy框架爬取多级页面
			
spides.py # -*- coding: utf-8 -*- import scrapy from weather.items import WeatherItem from scrapy.cr ...
 - 解决kbmMW Scheduler在任务中停止任务遇到的问题
			
procedure TCustomGridViewCameraDoc.InitSchedule; begin Scheduler.Schedule( procedure(const ASchedule ...
 - vue自学入门-6(vue jsx)
			
目录: vue自学入门-1(Windows下搭建vue环境) vue自学入门-2(vue创建项目) vue自学入门-3(vue第一个例子) vue自学入门-4(vue slot) vue自学入门-5( ...
 - Spark学习之路 (二十七)图简介[转]
			
test test test test test test test test test 图 基本概念 图是由顶点集合(vertex)及顶点间的关系集合(边edge)组成的一种数据结构. 这里的图并非 ...
 - mybatis及其与hibernate的对比
			
1.mybatis是支持普通SQL查询.存储过程.和高级映射的优秀持久层框架 它消除了JDBC代码和参数的手工设置,以及对结果集的检索 2.mybatis使用简单的XML或注解用于配置和原始映射,将接 ...
 - PAT (Basic Level) Practice (中文)1037 在霍格沃茨找零钱 (20 分)
			
如果你是哈利·波特迷,你会知道魔法世界有它自己的货币系统 —— 就如海格告诉哈利的:“十七个银西可(Sickle)兑一个加隆(Galleon),二十九个纳特(Knut)兑一个西可,很容易.”现在,给定 ...
 - 08-SV面向对象编程的高级技巧指南
			
1.原始类与扩展类 (1)原始类被称为父类或者超类,扩展类被称为派生类或者子类.扩展类可以直接访问原始类和其本身的所有变量,应该将原始类中的子程序定义成虚拟的,这样它们就可以在扩展类中重定义.new函 ...
 - Time series data mining
			
from here 论文Timeseries data mining(2012)中提出:时间序列数据挖掘包括7个基本任务和3个基础问题: 7 tasks: query by content clust ...