HDU 5950 Recursive sequence 递推转矩阵
Recursive sequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2882 Accepted Submission(s): 1284
Each case contains only one line with three numbers N, a and b where N,a,b < 231 as described above.
In the first case, the third number is 85 = 2*1十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.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=,maxn=;
struct Matrix
{
ll m[maxn][maxn];
Matrix()
{
memset(m,,sizeof(m));
}
void init()
{
for(int i=; i<maxn; i++)
for(int j=; j<maxn; j++)
m[i][j]=(i==j);
}
Matrix operator +(const Matrix &b)const
{
Matrix c;
for(int i=; i<maxn; i++)
{
for(int j=; j<maxn; j++)
{
c.m[i][j]=(m[i][j]+b.m[i][j])%mod;
}
}
return c;
}
Matrix operator *(const Matrix &b)const
{
Matrix c;
for(int i=; i<maxn; i++)
{
for(int j=; j<maxn; j++)
{
for(int k=; k<maxn; k++)
{
c.m[i][j]=(c.m[i][j]+(m[i][k]*b.m[k][j])%mod)%mod;
}
}
}
return c;
}
Matrix operator^(const ll &t)const
{
Matrix ans,a=(*this);
ans.init();
ll n=t;
while(n)
{
if(n&) ans=ans*a;
a=a*a;
n>>=;
}
return ans;
}
};
int main()
{
int t;
ll n,m,a,b;
scanf("%d",&t);
while(t--)
{
scanf("%lld %lld %lld",&n,&a,&b);
if(n==)
{
cout<<a%mod<<endl;
continue;
}
if(n==)
{
cout<<b%mod<<endl;
continue;
}
Matrix temp;
temp.m[][]=,temp.m[][]=,temp.m[][]=,temp.m[][]=,temp.m[][]=,temp.m[][]=;temp.m[][]=;
temp.m[][]=,temp.m[][]=,temp.m[][]=,temp.m[][]=,temp.m[][]=,temp.m[][]=;temp.m[][]=;
temp.m[][]=,temp.m[][]=,temp.m[][]=,temp.m[][]=,temp.m[][]=,temp.m[][]=;temp.m[][]=;
temp.m[][]=,temp.m[][]=,temp.m[][]=,temp.m[][]=,temp.m[][]=,temp.m[][]=;temp.m[][]=;
temp.m[][]=,temp.m[][]=,temp.m[][]=,temp.m[][]=,temp.m[][]=,temp.m[][]=;temp.m[][]=;
temp.m[][]=,temp.m[][]=,temp.m[][]=,temp.m[][]=,temp.m[][]=,temp.m[][]=;temp.m[][]=;
temp.m[][]=,temp.m[][]=,temp.m[][]=,temp.m[][]=,temp.m[][]=,temp.m[][]=;temp.m[][]=;
Matrix aa,bb;
bb.m[][]=b%mod;
bb.m[][]=a%mod;
bb.m[][]=;
bb.m[][]=;
bb.m[][]=;
bb.m[][]=;
bb.m[][]=;
aa=temp^(n-);
aa=aa*bb;
cout<<aa.m[][]%mod<<endl;
}
return ;
}
HDU 5950 Recursive sequence 递推转矩阵的更多相关文章
- hdu 5950 Recursive sequence 递推式 矩阵快速幂
题目链接 题意 给定\(c_0,c_1,求c_n(c_0,c_1,n\lt 2^{31})\),递推公式为 \[c_i=c_{i-1}+2c_{i-2}+i^4\] 思路 参考 将递推式改写\[\be ...
- HDU 5860 Death Sequence(递推)
HDU 5860 Death Sequence(递推) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5860 Description You ...
- HDU 5950 Recursive sequence 【递推+矩阵快速幂】 (2016ACM/ICPC亚洲区沈阳站)
Recursive sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- HDU 5950 - Recursive sequence - [矩阵快速幂加速递推][2016ACM/ICPC亚洲区沈阳站 Problem C]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5950 Farmer John likes to play mathematics games with ...
- HDU 5950 Recursive sequence(矩阵快速幂)
题目链接:Recursive sequence 题意:给出前两项和递推式,求第n项的值. 题解:递推式为:$F[i]=F[i-1]+2*f[i-2]+i^4$ 主要问题是$i^4$处理,容易想到用矩阵 ...
- HDU - 5950 Recursive sequence(二项式+矩阵合并+矩阵快速幂)
Recursive sequence Farmer John likes to play mathematics games with his N cows. Recently, they are a ...
- hdu 5950 Recursive sequence 矩阵快速幂
Recursive sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- hdu 5860 Death Sequence(递推+脑洞)
Problem Description You may heard of the Joseph Problem, the story comes from a Jewish historian liv ...
- HDU 5950 Recursive sequence(矩阵快速幂)题解
思路:一开始不会n^4的推导,原来是要找n和n-1的关系,这道题的MOD是long long 的,矩阵具体如下所示 最近自己总是很坑啊,代码都瞎吉坝写,一个long long的输入写成%d一直判我TL ...
随机推荐
- CSS综合用法
div 居中 {position: absolute; top: 50%; left: 50%; margin-top: -180px; margin-left: -160px;}
- Objective -C Object initialization 对象初始化
Objective -C Object initialization 对象初始化 1.1 Allocating Objects 分配对象 Allocation is the process by w ...
- Vue 拦截器的使用
拦截器 可以全局进行拦截器设置.拦截器在发送请求前或响应返回时做一些特殊的处理. 拦截器的注册 Vue.http.interceptors.push({ request: function ( req ...
- xamarin 学习笔记02- IOS Simulator for windows 安装
微软发布了在window下的ios模拟器 下载 ios模拟器 并安装在windows系统上. Xamarin for Visual Studio 和 网络上的 Mac 中的 Xamarin.iOS 开 ...
- 【Gambit】Gambit使用教程
第一章 Gambit使用 Gambit介绍 网格的划分使用Gambit软件,首先要启动Gambit,在Dos下输入Gambit <filemane>,文件名如果已经存在,要加上参数-old ...
- org.springframework.orm.hibernate4.support.OpenSessionInterceptor
/* * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Vers ...
- 理解 call, apply 的用法
callcall() 方法使用一个指定的 this 值和单独给出的一个或多个参数来调用一个函数. function list() { return Array.prototype.slice.call ...
- laravel如何自定义控制器目录
默认控制器在App\Http\Controllers目录下,如何自定义目录呢? 首先我们看一下laravel的请求周期 我们看一下服务提供者RouteServicePrivder文件中的一个函数 /* ...
- 使用GetLogicalDrives获取卷标
#include<stdio.h> #include<windows.h> int main() { DWORD dwLogical= GetLogicalDrives(); ...
- laravel JWTAuth实现api接口鉴权(基础篇)
官网:https://jwt-auth.readthedocs.io 参考:https://learnku.com/articles/10885/full-use-of-jwt#99529f 1.to ...