cout 和 printf 在 C++ 中的实现:四舍六入五随缘。比如 printf("%.0lf\n", x=1.5) => 1。

标准做法:printf("%d\n", (int)(x+0.5))

矩阵乘法

由 \(a_n=2a_{n-3}+a_{n-1}\) 得矩阵转移方程:

\[\begin{bmatrix} a_n & a_{n-1} & a_{n-2} \end{bmatrix} = \begin{pmatrix} 1 & 1 & 0 \\ 0 & 0 & 1 \\ 2 & 0 & 0 \end{pmatrix} \times \begin{bmatrix} a_{n-1} & a_{n-2} & a_{n-3} \end{bmatrix}
\]

这里采用 [] 表示 \(1\times 3\) 矩阵,() 表示 \(3\times 3\) 矩阵。

ll p[5][5], b[5][5], d[5][5], t[5][5];

memset(p, 0, sizeof p), memset(b, 0, sizeof b), memset(d, 0, sizeof d);
for (int i=1; i<=3; i++) b[i][i]=1ll; // unit matrix
p[1][1]=1ll, p[1][2]=1ll, p[1][3]=0ll;
p[2][1]=0ll, p[2][2]=0ll, p[2][3]=1ll;
p[3][1]=2ll, p[3][2]=0ll, p[3][3]=0ll; // transition matrix
d[1][1]=6ll, d[1][2]=1ll, d[1][3]=3ll; // initial matrix, a_3, a_2, a_1 // n<=3 特判
if (n<=3) {printf("%d\n", d[1][4-n]); return 0; } // 矩阵快速幂
int K=n-3;
while (K>0){
if (K&1) {
// (b) *= (p)
memset(t, 0, sizeof t);
for (int i=1; i<=3; i++)
for (int j=1; j<=3; j++)
for (int k=1; k<=3; k++)
t[i][j]=(t[i][j]+b[i][k]*p[k][j]) % mod;
memcpy(b, t, sizeof b);
} // (p) = (p)^2
memset(t, 0, sizeof t);
for (int i=1; i<=3; i++)
for (int j=1; j<=3; j++)
for (int k=1; k<=3; k++)
t[i][j]=(t[i][j]+p[i][k]*p[k][j]) % mod;
memcpy(p, t, sizeof p); K>>=1;
} // [t] = [d] * (b)
memset(t, 0, sizeof t);
for (int i=1; i<=3; i++)
for (int j=1; j<=3; j++)
t[1][i]=(t[1][i]+d[1][j]*b[j][i]) % mod;
printf("%lld\n", t[1][1]);

9-10 November的更多相关文章

  1. 各个版本 Windows 10 系统中自带的 .NET Framework 版本

    原文各个版本 Windows 10 系统中自带的 .NET Framework 版本 Windows 名称 Windows 版本 自带的 .NET Framework 版本 Windows 10 Oc ...

  2. centos各版本信息

    CentOS version Architectures RHEL base Kernel CentOS release date RHEL release date Delay (days) 2.1 ...

  3. 获取机器安装.NET版本的几种方式

    当调查应用程序问题时,通常需要先确认目标机器所安装的 .NET Framework 的版本.可以通过如下方式来确认版本号: 通过控制面板安装程序查询 通过查询注册表获取版本信息 通过查看安装目录获取版 ...

  4. SNMP进阶

    管理信息库:MIB 我们要扩展mib首先必须清楚mib是如何定义的,用的什么语言,有哪些约定,遵循哪些规则等等.这些基本东西掌握过后,我们就可以很轻松的来写自己的mib文件了. 所谓管理信息库,或者M ...

  5. Windows、VS 与 .net

    原文地址:https://msdn.microsoft.com/en-us/library/bb822049(v=vs.110).aspx .NET Framework version CLR ver ...

  6. 检测电脑安装的net framework版本

    https://msdn.microsoft.com/en-us/library/hh925568(v=vs.110).aspx To find .NET Framework versions by ...

  7. News: Visual Studio Code support debugging Linux Apps

    http://arstechnica.com/information-technology/2015/11/visual-studio-now-supports-debugging-linux-app ...

  8. PostgreSQL中initdb做了什么

    在使用数据库前,是启动数据库,启动数据库前是initdb(初始化数据库):一起来看一下initdb做了什么吧. 初始化数据库的操作为: ./initdb -D /usr/local/pgsql/dat ...

  9. ### Paper about Event Detection

    Paper about Event Detection. #@author: gr #@date: 2014-03-15 #@email: forgerui@gmail.com 看一些相关的论文. 1 ...

  10. authbind start tomcat services as user with less that 1024 ports. linux常规用户使用tomcat的80端口

    Start tomcat services using authbind this will allow user to start ports less than 1024 we do not ne ...

随机推荐

  1. 一些重温CSS需要注意的小细节

    <!-- CSS是用于描述页面展示的语言 字体.颜色.大小.间距,将内容分为多列 或者简单的动画及其他的装饰效果 决定了长啥样 html房子的骨架 css负责装修 怎么装修一个房子呢? 首先就是 ...

  2. [转帖]100G QSFP28与CFP,CFP2,CFP4光模块的比较

    100G QSFP28与CFP,CFP2,CFP4光模块的比较 https://www.eefocus.com/etulink/blog/17-09/423967_5c520.html 数据中心网络发 ...

  3. 2019.07.06 纪中_B

    今天的题看起来都很简单,结果就爆炸了 做题时:怎么都是图论??? 结果最后好多是DP(最恐怖的是还有我没学过的状压DP) 2019.07.06[NOIP提高组]模拟 B 组 做了两题(稍微腐败了一下) ...

  4. 【PDF】手写字与识别字重叠

    [PDF]手写字与识别字重叠 前言 同学平时上课用iPad记笔记,考试之前导出为PDF发给我后,我用PDF打开,发现可以直接Ctrl+F搜索一些词语.一直不知道是怎么做到的,毕竟里面的字都是手写的,不 ...

  5. 用yum快速搭建LAMP平台与虚拟域名配置

    实验环境: [root@nmserver-7 html]# cat /etc/redhat-release CentOS release 7.3.1611 (AltArch) [root@nmserv ...

  6. SQL性能优化概要

    基本概要 1.查询的模糊匹配时,避免使用Like '%开头',使得索引失效 2.索引问题 ◆ 避免对索引字段进行运算操作和使用函数 ◆ 避免在索引字段上使用not,<>,!= ◆ 避免在索 ...

  7. 广播即时通信src和des

    package 第十二章; import java.io.IOException; import java.net.DatagramPacket; import java.net.InetAddres ...

  8. 【学习总结】快速上手Linux玩转典型应用-第3章-CentOS的安装

    课程目录链接 快速上手Linux玩转典型应用-目录 目录 1. 虚拟机是什么 2. 在虚拟机中安装CentOS 3. 云服务器介绍 ================================== ...

  9. 【 React - 1/100 】React绑定事件this指向问题--改变state中的值

    /** * 报错: * Cannot read property 'setState' of undefined * 原因: this指向不一致.btnAddCount中的this 和render中的 ...

  10. python二维码模块(qrcode)

    qrcode模块安装 运行命令行工具(cmd),使用pip安装工具分别安装qrcode. pip install qrcode 先来个简单的例子 import qrcode # 二维码内容 data ...