• 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("
    
    ----------
    
    ")
    #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;
    }
    

  • 相关阅读:
    Python异常捕捉try except else finally有return时执行顺序探究
    为什么在Python的线程内调用sys.exit()时不退出?
    Hadoop集群上用户使用crontab时候失败
    记一次--------spark 读 mysql 报错no suitable driver
    通用权限sql设计
    union all 对结果进行分类展示
    雷达图
    常用语句
    oracle中计算两个日期的相差天数、月数、年数、小时数、分钟数、秒数等
    icell设计器发送邮件不成功
  • 原文地址:https://www.cnblogs.com/bingoyes/p/11251062.html
Copyright © 2020-2023  润新知