Recursive sequence ---矩阵快速幂

本文介绍了一种解决递归数列问题的方法,通过构建特定矩阵并使用快速幂运算,有效地计算出数列中第N项的值。文章详细展示了如何根据题目给出的递推公式构建矩阵,并提供了完整的AC代码实现。

Farmer John likes to play mathematics games with his N cows. Recently, they are attracted by recursive sequences. In each turn, the cows would stand in a line, while John writes two positive numbers a and b on a blackboard. And then, the cows would say their identity number one by one. The first cow says the first number a and the second says the second number b. After that, the i-th cow says the sum of twice the (i-2)-th number, the (i-1)-th number, and i4. Now, you need to write a program to calculate the number of the N-th cow in order to check if John’s cows can make it right.
Input
The first line of input contains an integer t, the number of test cases. t test cases follow.
Each case contains only one line with three numbers N, a and b where N,a,b < 231 as described above.
Output
For each test case, output the number of the N-th cow. This number might be very large, so you need to output it modulo 2147493647.
Sample Input
2
3 1 2
4 1 10
Sample Output
85
369

Hint
In the first case, the third number is 85 = 21十2十3^4.
In the second case, the third number is 93 = 2
1十1*10十3^4 and the fourth number is 369 = 2 * 10 十 93 十 4^4.

先根据题意得到递推公式即:f(n)=2*f(n-2)+f(n-1)+i^4
然后在构建那个矩阵(直接构建就行了),剩下的就是套模板了
下面是推导那个矩阵过程
在这里插入图片描述
在这里插入图片描述

ac代码:

#include<iostream>
#include<cstdio> 
#include<cstring>
using namespace std;
typedef long long ll;
const ll mod=2147493647;//根据题意进行mod 
struct node{
	ll p[10][10];
};
int n=7;
node q(node a,node b)
{//两个矩阵相乘。 
	node ans;
	memset(ans.p,0,sizeof(ans.p));
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			for(int k=1;k<=n;k++){
				ans.p[i][j]=(ans.p[i][j]+a.p[i][k]*b.p[k][j]%mod+mod)%mod;
			}
		}
	}
	return ans;
}
node p(node a,ll nn)
{//快速幂 
	node res;
	memset(res.p,0,sizeof(res.p));
	for(int i=1;i<=n;i++)res.p[i][i]=1;
	while(nn){
		if(nn&1)res=q(res,a);
		nn>>=1;
		a=q(a,a);
	}
	return res;
}
int main()
{
	node a;
	memset(a.p,0,sizeof(a.p));//清空为0,下面是对a数组进行赋值初始化 
	a.p[1][2]=1;
	a.p[2][1]=2;a.p[2][2]=1;a.p[2][3]=1;a.p[2][4]=4;a.p[2][5]=6;a.p[2][6]=4;a.p[2][7]=1;
	a.p[3][3]=1;a.p[3][4]=4;a.p[3][5]=6;a.p[3][6]=4;a.p[3][7]=1;
	a.p[4][4]=1;a.p[4][5]=3;a.p[4][6]=3;a.p[4][7]=1;
	a.p[5][5]=1;a.p[5][6]=2;a.p[5][7]=1;
	a.p[6][6]=1;a.p[6][7]=1;
	a.p[7][7]=1;
	int t;
	cin>>t;
	while(t--)
	{
		node b;
		ll k,aa,bb;
		scanf("%lld%lld%lld",&k,&aa,&bb);
		if(k==1){//特殊情况 
			printf("%d\n",aa);
			continue;
		}
		if(k==2){//特殊对待 
			printf("%d\n",bb);
			continue;
		}
		node ans=p(a,k-2); 
		memset(b.p,0,sizeof(b.p));
		b.p[1][1]=aa;b.p[2][1]=bb;b.p[3][1]=16;b.p[4][1]=8;
		b.p[5][1]=4;b.p[6][1]=2;b.p[7][1]=1; 
		ans=q(ans,b);//注意顺序 ,反了就不对了 
		printf("%lld\n",ans.p[2][1]);//我的f(n)是在第二行,所以要输出ans.p[2][1]。 
	}
	return 0;
}

标题基于SpringBoot的马术俱乐部管理系统设计与实现AI更换标题第1章引言介绍马术俱乐部管理系统的研究背景、意义、国内外研究现状、论文方法及创新点。1.1研究背景与意义阐述马术俱乐部管理系统对提升俱乐部管理效率的重要性。1.2国内外研究现状分析国内外马术俱乐部管理系统的发展现状及存在的问题。1.3研究方法以及创新点概述本文采用的研究方法,包括SpringBoot框架的应用,以及系统的创新点。第2章相关理论总结和评述与马术俱乐部管理系统相关的现有理论。2.1SpringBoot框架理论介绍SpringBoot框架的基本原理、特点及其在Web开发中的应用。2.2数据库设计理论阐述数据库设计的基本原则、方法以及在管理系统中的应用。2.3马术俱乐部管理理论概述马术俱乐部管理的基本理论,包括会员管理、课程安排等。第3章系统设计详细描述马术俱乐部管理系统的设计方案,包括架构设计、功能模块设计等。3.1系统架构设计给出系统的整体架构,包括前端、后端和数据库的交互方式。3.2功能模块设计详细介绍系统的各个功能模块,如会员管理、课程管理、预约管理等。3.3数据库设计阐述数据库的设计方案,包括表结构、字段设计以及数据关系。第4章系统实现介绍马术俱乐部管理系统的实现过程,包括开发环境、编码实现等。4.1开发环境搭建介绍系统开发所需的环境,包括操作系统、开发工具等。4.2编码实现详细介绍系统各个功能模块的编码实现过程。4.3系统测试与调试阐述系统的测试方法、测试用例以及调试过程。第5章系统应用与分析呈现马术俱乐部管理系统的应用效果,并进行性能分析。5.1系统应用情况介绍系统在马术俱乐部中的实际应用情况。5.2系统性能分析从响应时间、并发处理能力等方面对系统性能进行分析。5.3用户反馈与改进收集用户反馈,提出系统改进建议。第6章结论与展望总结马术俱乐部管理系统的设计与实现成果,并展望未来的研究
### Git 子模块更新失败的原因分析 当 `git submodule update --init --recursive --progress` 执行失败时,可能涉及多种潜在原因。以下是常见的几种情况及其对应的解决方案: #### 1. **网络连接不稳定** 如果网络条件较差或者目标仓库不可达,则可能导致子模块无法正常拉取数据。这种情况下可以通过增加超时时间来尝试解决问题。 ```bash git config http.lowSpeedLimit 0 git config http.lowSpeedTime 999999 git submodule update --init --recursive --progress ``` 上述配置调整了 HTTP 的低速限制和等待时间[^5]。 #### 2. **本地Git版本过旧** 某些较老版本的 Git 可能存在兼容性问题,特别是对于带有大量嵌套子模块的情况。建议检查当前使用的 Git 版本并考虑升级至最新稳定版。 ```bash # 查看现有版本号 git --version # 如果低于推荐标准(如2.17.1),则需更新工具链 if [ $(echo "$(git --version | cut -d ' ' -f 3)" "<" "2.17.1") ]; then echo "Please upgrade your GIT client." fi # 更新指令依据具体环境而定 sudo apt-get install git # 对于Debian/Ubuntu系统 brew upgrade git # macOS Homebrew用户 choco upgrade git # Windows Chocolatey包管理器 ``` 注意,在Windows平台上应特别关注官方发布的安装程序或通过`git update-git-for-windows`完成自动化流程[^4]。 #### 3. **未初始化的工作区状态异常** 有时即使运行了必要的前置操作仍会遭遇错误提示,这通常是因为工作树尚未被适当设置好所致。重新初始化整个项目结构往往能够修复此类状况。 ```bash rm -rf .git/modules/* # 清理残留记录 find . -name ".git*" -type d -exec rm -r {} \; # 彻底移除隐藏文件夹下的.git目录 git init # 创建新的裸库实例 git submodule foreach --recursive 'git remote set-url origin <correct_url>' || true git submodule sync # 同步URL链接地址信息 git submodule update --init --recursive --force --progress ``` 以上脚本片段展示了如何强制刷新所有关联关系以及重置远端路径映射表单[^2]。 #### 4. **权限不足或其他外部干扰因素** 确认执行者具备足够的访问权去读写相关资源;另外还需排查防火墙策略是否屏蔽掉必要通信端口等情形。 --- ### 总结说明 综上所述,针对`git submodule update --init --recursive --progress`命令失败的现象可以从四个方面入手诊断处理:优化网络参数设定、验证客户端软件级别适配度、修正受损的基础架构布局还有排除周边安全隐患影响[^1][^2][^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值