• A


    HDU - 1575

    很裸的矩阵乘法
    对角线一共只有两条,试一下就好了

    
    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<cstring>
    using namespace std;
    
    const int mod = 9973;
    
    int n;
    
    struct jz{
        int g[20][20];
        void init(){
            memset(g,0,sizeof(g));
        }
        void one(){
            memset(g,0,sizeof(g));
            for(int i = 1; i <= n; ++ i) g[i][i] = 1;
        }
    };
    jz operator * (jz a, jz b){
        jz c; c.init();
        for(int i = 1; i <= n; ++ i)
        for(int j = 1; j <= n; ++ j)
        for(int k = 1; k <= n; ++ k)
        c.g[i][j] += (a.g[i][k] * b.g[k][j]) % mod, c.g[i][j] %= mod;
        return c;
    }
    jz ksm(jz x,int y){
        jz z; z.one();
        while(y){
            if(y & 1) z = z * x;
            y >>= 1;
            x = x * x;
        }
        return z;
    }
    
    int k;
    jz a;
    
    int main(){
        int T; scanf("%d",&T);
        while(T --){
            scanf("%d%d",&n,&k);
            
            for(int i = 1; i <= n; ++ i)
            for(int j = 1; j <= n; ++ j) 
            scanf("%d",&a.g[i][j]), a.g[i][j] %= mod;
            
            a = ksm(a,k);
            
            int ans = 0;
            for(int i = 1; i <= n; ++ i) 
            ans += a.g[i][i], ans %= mod;
            
            printf("%d
    ",ans);
        }
        return 0;
    }
    
    
    
  • 相关阅读:
    Puppeteer--API
    Puppeteer--性能优化
    Puppeteer--代码示例(3)
    Puppeteer--代码示例(2)
    Puppeteer--代码示例(1)
    Puppeteer--等待加载
    Puppeteer--创建实例
    Puppeteer--爬坑记录
    Puppeteer--参考介绍
    vue.js的的回到顶部
  • 原文地址:https://www.cnblogs.com/zzhzzh123/p/13355409.html
Copyright © 2020-2023  润新知