zoukankan      html  css  js  c++  java
  • 求矩阵的模n^3logn

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <vector>
    
    using namespace std;
    typedef __int64 lld;
    const int MOD = 998244353;
    const int N = 20;
    
    struct Mat {
        lld a[N][N];
        void init(int _a[N][N], int n) {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    a[i][j] = _a[i][j];
                }
            }
        }
    
        lld * operator [] (int x) {
            return a[x];
        }
    }AC, C;
    
    lld Det(Mat &A, int n) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                C[i][j] = A[i][j] % MOD;
            }
        }
        lld ret = 1;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                while (C[j][i]) {
                    for (int t = C[i][i] / C[j][i], k = 0; k < n; k++) {
                        printf("t  = %d
    ", t);
                        C[i][k] = (C[i][k] - C[j][k] * t) % MOD;
                        swap(C[i][k], C[j][k]);
                    }
                    ret = - ret;
                }
                for(int o = 0; o < n; o ++){
                    for(int z = 0; z < n; z ++) printf("%d ", C[o][z]); printf("
    ");
                }
            }
            if (C[i][i] == 0) return 0;
            ret = ret * C[i][i] % MOD;
        }
        return ret;
    }
    
    
    int main(){
        int a[N][N] = {
            {2,3,4},
            {3,4,2},
            {4,2,3}
        };
        int cur = 4;
        AC.init(a, cur - 1);
        printf("%I64d
    ", Det(AC, cur - 1));
    }
    

      

  • 相关阅读:
    每日日报24
    每日日报23
    每日日报22
    链路层:MAC 地址
    应用层:电子邮件
    应用层:HTTP 协议
    应用层:DNS 域名系统
    运输层:TCP 拥塞控制
    运输层:拥塞控制原理
    JAVA学习日记26-0731
  • 原文地址:https://www.cnblogs.com/acmood/p/4681087.html
Copyright © 2011-2022 走看看