zoukankan      html  css  js  c++  java
  • [ICPC2020济南A] Matrix Equation

    [ICPC2020济南A] Matrix Equation - 线性基

    Description

    给一个 A 矩阵 一个 B 矩阵(矩阵元素为 0 或 1),求有多少个 C 矩阵 满足 A X C = B . C (叉乘 和 直积)。(n le 200)

    Solution

    C 的每一列是相互无关的,分开考虑,转化为解 (n) 个线性方程组的个数,实际上就是求系数矩阵的秩,用 bitset 线性基即可

    #include <bits/stdc++.h>
    using namespace std;
    
    #define int long long
    
    const int mod = 998244353;
    
    int a[205][205], b[205][205];
    
    int qpow(int p, int q)
    {
        return (q & 1 ? p : 1) * (q ? qpow(p * p % mod, q / 2) : 1) % mod;
    }
    
    struct LinearBase
    {
        // bitset<205> a[205];
        vector<bitset<205>> a;
    
        LinearBase()
        {
            a.resize(205);
        }
        int ans = 0;
        void insert(bitset<205> k)
        {
            for (int j = 204; j >= 0; j--)
            {
                if ((k >> j)[0])
                {
                    if (a[j] == 0)
                    {
                        a[j] = k;
                        ans++;
                        break;
                    }
                    else
                    {
                        k ^= a[j];
                    }
                }
            }
        }
    };
    
    signed main()
    {
        int n;
        cin >> n;
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
                cin >> a[i][j];
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
                cin >> b[i][j];
    
        int ans = 0;
        for (int c = 1; c <= n; c++)
        {
            LinearBase lb;
            for (int i = 1; i <= n; i++)
            {
                bitset<205> tmp;
                for (int j = 1; j <= n; j++)
                {
                    tmp[j] = a[i][j];
                    if (i == j && b[i][c])
                        tmp[j] = 1 - tmp[j];
                }
                lb.insert(tmp);
            }
            ans += n - lb.ans;
        }
    
        cout << qpow(2, ans) << endl;
    }
    
    
  • 相关阅读:
    文件重名问题
    文件上传
    回顾IO流
    Freemarker
    中文乱码问题
    Filter(过滤器)
    Ajax
    jQuery
    普华操作系统,开机无法进入桌面程序; 解决多次source /etc/profile的烦恼
    C++ 文件类型判别错误,将目录文件识别为普通文件
  • 原文地址:https://www.cnblogs.com/mollnn/p/14563060.html
Copyright © 2011-2022 走看看