[poj3735 Training little cat]【矩阵快速幂】

poj 3735 Training little cats 构造矩阵+稀疏矩阵加速连乘+矩阵快速幂 poj 3735 Training little cats 构造矩阵+稀疏矩阵加速连乘 题目链接:http://poj.org/problem?id=3735 题面描述: Training little cats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13366 阅读详情

好题重温。
唯一的坑点是k可能小于0…

#include <cstdio>
#include <cstring>
#include <algorithm>

const int MAX = 101;
typedef long long ll;

struct mat {
    ll a[MAX][MAX];

    mat() {
        memset(a, 0, sizeof(a));
    }
    mat(int x) {
        memset(a, 0, sizeof(a));
        for (int i = 0; i < MAX; ++i) {
            a[i][i] = 1;
        }
    }

    mat operator+(const mat& B)const {
        mat res;
        for (int i = 0; i < MAX; ++i) {
            for (int j = 0; j < MAX; ++j) {
                res.a[i][j] = a[i][j] + B.a[i][j];
            }
        }
        return res;
    }

    mat operator*(const mat& B)const {
        mat res;
        for (int i = 0; i < MAX; ++i) {
            for (int j = 0; j < MAX; ++j) {
                if (a[i][j]) {
                    for (int k = 0; k < MAX; ++k) {
                        res.a[i][k] += a[i][j] * B.a[j][k];
                    }
                }
            }
        }
        return res;
    }
} E(1);

mat fastpow(mat a, int m) {
    mat res(1);
    while (m) {
        if (m & 1) res = res * a;
        m >>= 1;
        a = a * a;
    }
    return res;
}

int main() {
    char op;
    int c1, c2;
    int n, m, k;
    while (~scanf(" %d %d %d", &n, &m, &k)) {
        if (n == 0 && m == 0 && k == 0) break;
        mat cat, b(1);
        cat.a[n][0] = 1;
        while (k-- > 0) {
            scanf(" %c %d", &op, &c1);
            if (op == 'g') {
                ++b.a[c1-1][n];
            } else if (op == 'e') {
                memset(b.a[c1-1], 0, sizeof(b.a[c1-1]));
            } else {
                scanf(" %d", &c2);
                std::swap(b.a[c1-1], b.a[c2-1]);
            }
        }
        cat = fastpow(b, m) * cat;
        printf("%lld", cat.a[0][0]);
        for (int i = 1; i < n; ++i) {
            printf(" %lld", cat.a[i][0]);
        }
        puts("");
    }

    return 0;
}
AD56XXR系列DAC驱动设计:SPI接口、寄存器配置与嵌入式工程实践 数模转换器(DAC)是嵌入式系统实现高精度模拟控制的核心器件,其性能取决于通信协议可靠性、寄存器配置准确性及硬件协同设计能力。基于SPI总线的电压输出型DAC广泛应用于工业控制、光模块偏置、传感器校准等场景,需兼顾静态精度、动态响应与低功耗特性。AD56XXR系列作为典型集成内部基准与多通道同步更新能力的12/14/16位DAC,支持轨到轨输出与灵活掉电模式,为资源受限MCU提供可移植固件范式。本文围绕SPI时序约束、16位指令字解析、LDAC同步机制及精度补偿策略展开,覆盖从硬件连接、初始化流程到量产级可 阅读详情

相关推荐

【从零开始玩量化1】AKShare: Python开源财经数据接口库

文章目录量化的第一步:数据AKShare介绍AKShare安装AKShare使用AKTools安装/使用结语 量化的第一步:数据 想要玩量化,第一步要有数据,这个数据可能是历史交易数据、财务数据、宏观数据等等。我们最终要做的,无非就是从数据中分析出有价值的信息,以便用来指导投资策略。 在获取数据的这条道路上,我走了很多弯路,尝试了各种方法:使用Tushare到放弃、自己写网易股票页面的爬虫,自己写申万行业数据的爬虫、自己写同花顺问财的爬虫、使用聚宽的免费数据API等等,直到最终,我发现了AKShare。 A

量化投资助手的博客 5万+

POJ 3735 Training little cats(矩阵快速幂)

Training little cats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11787 Accepted: 2892 Description Facer’s pet cat just gave birth to a brood of little cats. Hav...

weixin_30810583的博客 197

游程理论提取灾害事件特征V2---基于MATLAB语言的编程实现

游程理论,灾害事件,MATLAB

EWBA_GIS_RS_ER的博客 3798

POJ3735 Training little cats(矩阵快速幂)

Description Facer’s pet cat just gave birth to a brood of little cats. Having considered the health of those lovely cats, Facer decides to make the cats to do some exercises. Facer has well des

riba2534的博客 902

[渗透测试实战篇-4] RCE漏洞组合拳突破Getshell全解析

本文深入解析RCE漏洞组合拳在渗透测试中的实战应用,通过SSRF、XXE等漏洞串联技术突破Getshell的全过程。文章详细介绍了Java和PHP环境下的漏洞利用差异,以及防御绕过与权限维持的实用技巧,为安全研究人员提供全面的实战指导。

weixin_29211309的博客 358

Rust Reqwest+Rustls 自签名证书校验

所以这里必须保证reqwest引用的rustls库和本地工程一致。以上就是实现不校验签名的逻辑,后续自己可以在对应回调进行逻辑判断。

bawomingtian123的专栏 1380

poj 3735 Training little cats

<br /><br />Training little cats<br />Time Limit:2000MS<br /> <br />Memory Limit:65536K<br />Total Submissions:5815<br /> <br />Accepted:1423<br />Description<br />Facer's pet cat just gave birth to a brood of little cats. Having considered the health of t

喵呜的Blog 4399

告别手动改Hex!用Vector HexView命令行5分钟搞定固件数据“乾坤大挪移”

本文详细介绍了如何利用Vector HexView命令行工具快速实现嵌入式固件数据的自动化迁移,告别手动修改Hex文件的繁琐流程。通过实战案例和脚本示例,展示了如何5分钟内完成数据地址范围的重新映射,提升嵌入式开发效率,特别适用于烧录文件的内存布局调整。

weixin_30635053的博客 716

poj-3735-Training little cats-矩阵快速幂

Link:http://poj.org/problem?id=3735Training little catsTime Limit: 2000MS Memory Limit: 65536K Total Submissions: 11954 Accepted: 2951 Description Facer's pet cat just gave birth to a b

DylanJoe的博客 498

解码器选型参数,结构原理,工艺与注意问题总结

解码器芯片(Decoder Chip)是电子设备中的一个重要组件,通常用于处理、解释和输出存储在某种编码格式中的数据或信号。本文对解码器的工作原理,结构特点,工艺流程,选型参数及设计注意事项进行总结。

fydar的博客 1181

[特殊字符] 从零构建携程/飞猪机票价格爬虫:Python异步抓取与反爬对抗实战

在出行决策、竞品分析、价格预测模型训练等场景中,稳定获取携程(Ctrip)和飞猪(Fliggy)的实时机票价格波动数据是刚需。然而,这两大平台均部署了业界顶尖的反爬体系——包括但不限于:动态请求签名(SignToken设备指纹采集(UACanvasWebGL接口参数加密(X-Sign_abtestcookie混淆)频率限制与 IP 封禁(滑动窗口 + 行为检测)目录前言:为什么需要自建机票价格爬虫?一、技术选型与项目架构1.1 核心技术栈1.2 系统架构图(文字描述)1.3 法律与道德声明。

2201_76125261的博客 343

POJ3735 Training little cats - 矩阵快速幂 -稀疏矩阵乘法优化

Training little cats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 16336   Accepted: 3998 Description Facer’s pet cat just gave birth to a brood of little cats. Having conside...

太阳升起 505

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

POJ 3735 Training little cats (矩阵快速幂)

POJ 3735 Training little cats (矩阵快速幂)

Tc的专栏 1938

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

【矩阵快速幂专题】POJ 3735 Training little cats

http://poj.org/problem?id=3735 Training little cats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15535   Accepted: 3829 Description Facer's pet cat just gave birth t...

荷叶田田 345

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

POJ3735 Training little cats 矩阵快速幂

Description Facer's pet cat just gave birth to a brood of little cats. Having considered the health of those lovely cats, Facer decides to make the cats to do some exercises. Facer has well designed ...

Yerkeys的博客 255

POJ 3735 E - Training little cats POJ - 3735 矩阵构造

Facer's pet cat just gave birth to a brood of little cats. Having considered the health of those lovely cats, Facer decides to make the cats to do some exercises. Facer has well designed a set of move

Marcus-Bao的个人主页 701

Training little cats

http://poj.org/problem?id=3735 题解:、 因m的数据范围较大,用矩阵连乘。 构建矩阵模型,peanut[N] = {0,0,。。。。0,1}:即前n个数为0,最后一个数取1 matrix[N][N],初始化条件下为单位矩阵,。。。 对猫咪进行操作转化为在对矩阵peanut进行操作,一组操作过程转化为矩阵matrix,那么m次操作,即对peanut*(matrix...

无限迭代中...... 333

poj 3735 Training little cats(矩阵快速幂)

Description Facer's pet cat just gave birth to a brood of little cats. Having considered the health of those lovely cats, Facer decides to make the cats to do some exercises. Facer has well designe

浮躁的人,终究一事无成! 1230

poj_3735_Training little cats(矩阵快速幂)

Training little cats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8468   Accepted: 2033 Description Facer's pet cat just gave birth to a brood of little

Light_starlight 671

POJ3735-Training little cats

Training little cats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14605   Accepted: 3612 Description Facer's pet cat just gave birth to a brood of littl

wang_128的博客 425

poj 3735 Training little cats(构造矩阵)

Training little cats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8326   Accepted: 2004 Description Facer's pet cat just gave birth to a brood of little

WEYuLi的专栏 843

POJ 3735 Training little cats 解题报告(矩阵构造+快速幂优化)

Training little cats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9396   Accepted: 2249 Description Facer's pet cat just gave birth to a brood of little

SF-_- 的 ACM 博客 919

poj 3735Training little cats(矩阵快速幂 完成模拟 注意优化)

Training little cats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 12392   Accepted: 3049 Description Facer's pet cat just gave birth to a brood of little

GreyWings的博客 418

toj2861_Divisors_线性时间内计算n前约数的总和

/C++long long int a[10]={0,1,3,5,8,10}; long long int f(long long int m) { if (m<=5) return a[m]; long long sum = 0; long long int i; for (i = 1; i*i <= m; ++i) { sum += m/

When you go away 1054
上一篇: [hihoCoder 1014][Trie 树]Trie
下一篇: [BFS]HDU1044 Collect More Jewels
bit_line
博客等级 码龄12年 33粉丝 150原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值