题目链接:4920 Matrix multiplication
题目大意:给定两个n阶矩阵,求矩阵相乘后模3.
解题思路:因为矩阵模掉3后只有0,1,2三种情况。所以对于矩阵A,记录每一行中1,2的位置,借助bitset。矩阵B中每一列1,2的位置。然后对于结果中每个位置,只要考虑1∗1,1∗2,2∗1,2∗2的个数即可。
#include <cstdio>
#include <cstring>
#include <bitset>
#include <algorithm>
using namespace std;
const int maxn = 805;
int N, C[maxn][maxn];
bitset<maxn> x[maxn][2], y[maxn][2];
void init () {
......
阅读全文