惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threat Research - Cisco Blogs
Google DeepMind News
Google DeepMind News
H
Help Net Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
MyScale Blog
MyScale Blog
Webroot Blog
Webroot Blog
Stack Overflow Blog
Stack Overflow Blog
T
The Blog of Author Tim Ferriss
D
Docker
L
LangChain Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Know Your Adversary
Know Your Adversary
A
About on SuperTechFans
U
Unit 42
NISL@THU
NISL@THU
M
MIT News - Artificial intelligence
T
The Exploit Database - CXSecurity.com
K
Kaspersky official blog
Martin Fowler
Martin Fowler
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Hacker News - Newest:
Hacker News - Newest: "LLM"
Engineering at Meta
Engineering at Meta
Blog — PlanetScale
Blog — PlanetScale
Scott Helme
Scott Helme
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 【当耐特】
WordPress大学
WordPress大学
Attack and Defense Labs
Attack and Defense Labs
P
Proofpoint News Feed
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
TaoSecurity Blog
TaoSecurity Blog
B
Blog RSS Feed
小众软件
小众软件
G
Google Developers Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
SegmentFault 最新的问题
博客园 - 司徒正美
腾讯CDC
大猫的无限游戏
大猫的无限游戏
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Security @ Cisco Blogs
aimingoo的专栏
aimingoo的专栏
W
WeLiveSecurity
V
Vulnerabilities – Threatpost
N
News and Events Feed by Topic
Google Online Security Blog
Google Online Security Blog
Cisco Talos Blog
Cisco Talos Blog
C
Check Point Blog

秋实-Allenyou 的小窝

【笔记】人工智能与模式识别 复习笔记 - 秋实-Allenyou 的小窝 【教程】使用 Keyd 将 Copilot 键映射为可用的组合键并修复触摸板防误触失效问题 机械革命无界 15X 的 Arch Linux 开荒指南 我在用什么?(2026 版) - 秋实-Allenyou 的小窝 关于 Next.js SSG 生成 RSS Feed 文件的另一思路 从零开始的 NixOS 体验 - 秋实-Allenyou 的小窝 2025:迷茫中转向 - 秋实-Allenyou 的小窝 我在用什么?(2025 版) - 秋实-Allenyou 的小窝 【杂谈】关于 AIGC 的一些思考 - 秋实-Allenyou 的小窝 【记录】一种在主机通过 Docker 容器名解析容器 IP 的方法 【记录】如何在 Next.js 中优雅的调用 Matomo 统计 从信号与系统角度看 OI/XCPC 中的傅里叶变换运用 - 秋实-Allenyou 的小窝 【杂谈】答《博客作者呀,我想采访你这 9 个问题!》 - 秋实-Allenyou 的小窝 使用 Golang 重写 gh-proxy - 秋实-Allenyou 的小窝 FurryCTF 2024 寒假赛 调试窗口 题解 2024:“我”的大学生活 - 秋实-Allenyou 的小窝 【游记】CCPC 2024 重庆站尾杀记 - 秋实-Allenyou 的小窝 【游记】ICPC 2024 亚洲区域赛南京站打铁记 - 秋实-Allenyou 的小窝 【杂谈】这次 Furrygooo 结束后我的一些体验 - 秋实-Allenyou 的小窝 【教程】使用阿里云 OSS + CDN 加速 Gravatar 【记录】 一次罗技鼠标驱动冲突问题的排查经历 - 秋实-Allenyou 的小窝 【记录】我是如何用 Next.js 重构我的博客的 - 秋实-Allenyou 的小窝 【教程】如何用 Git 快速搭建简单的 CI - 秋实-Allenyou 的小窝 我的DN42 Peering信息 - 秋实-Allenyou 的小窝 【进度】博客重构计划 - 秋实-Allenyou 的小窝 这是一个正经的2023总结 - 秋实-Allenyou 的小窝 【题解】Luogu P9769 [HUSTFC 2023] 简单的加法乘法计算题 2023新年谜题总结 - 秋实-Allenyou 的小窝 【教程】浅谈Linux服务器的一些基础安全技巧 - 秋实-Allenyou 的小窝 Goodbye, 2022~ - 秋实-Allenyou 的小窝 【教程】使用 Docker 开服,优雅地隔离不同版本JDK - 秋实-Allenyou 的小窝 【旧文补档】2020年终总结 & 2021新年计划 - 秋实-Allenyou 的小窝 【旧文补档】写个脚本监控你的VPS SolusVM面板适用 - 秋实-Allenyou 的小窝 【旧文补档】建立自己的私人网盘!在CentOS VPS上安装NextCloud - 秋实-Allenyou 的小窝 【旧文补档】2019,再见!2020,你好! - 秋实-Allenyou 的小窝 【旧文补档】新一代USB来袭,一起捋一捋USB的“前世今生” - 秋实-Allenyou 的小窝
【旧文补档】矩阵学习笔记 - 秋实-Allenyou 的小窝
2019-10-12 · via 秋实-Allenyou 的小窝

【旧文补档】矩阵学习笔记

2019/10/12

本文最后修改于 2432 天前,请注意文章内容的时效性。

前言

矩阵是线性代数的内容,在 OI 竞赛中有广泛运用。

常见知识点:

  • 矩阵乘法
  • 矩阵快速幂
  • 矩阵加速递推

定义

  • 矩阵: 类似一个的二维数组。
  • 方阵: 一个的矩阵。
  • 矩阵乘法: 将一个的矩阵和一个的矩阵相乘,得到一个的矩阵。

C++定义

#include <bits/stdc++.h>
using namespace std;
struct matrix {
private:
    int **a; // 二维数组指针
    int r, c;  // r * c 矩阵
public:
    matrix(int m, int n) {
        r = m;
        c = n;
        a = new int*[r]; // 动态二维数组
        for (int i = 0; i < r; i++) {
            a[i] = new int[c];
            for (int j = 0; j < c; j++) {
                a[i][j] = 0;
            }
        }
    }
    int &at(const int &x, const int &y) { return a[x][y]; }
    int &row() { return r; }
    int &cal() { return c; }
    // 重载赋值运算符
    void operator=(matrix M) {
        r = M.row();
        c = M.cal();
        a = new int*[r];
        for (int i = 0; i < r; i++) {
            a[i] = new int[c];
            for (int j = 0; j < c; j++) {
                a[i][j] = M.at(i, j);
            }
        }
    }
    // 重载矩阵乘法
    matrix operator*(matrix &M) {
        matrix t(r, M.cal());
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < M.cal(); j++) {
                int p = 0;
                for (int o = 0; o < c; o++) {
                    p += a[i][o] * M.at(o, j);
                }
                t.at(i, j) = p;
            }
        }
        return t;
    }
    // 输出矩阵
    void print() {
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                printf("%d ", a[i][j]);
            }
            printf("\n");
        }
    }
};
// 矩阵快速幂
matrix quickpow(matrix mat, int n) {
    matrix base = mat, ans = mat;
    --n;
    while (n) {
        if (n & 1) {
            ans = ans * base;
            --n;
        }
        base = base * base;
        n >>= 1;
    }
    return ans;
}

用途

加速递推

比如 Fibonacci 的递推就可以用这个加速。

Fibonacci 第 n 项

定义为数列的第项。

则​

可推出

由矩阵的定义可得到

然后就可以用矩阵快速幂愉快地加速啦^_^

Fibbonacci 前 n 项和

定义为数列的第项。

定义为数列前项之和。

可推得

由矩阵定义可得

其他

待补充我还不会