题目链接:hdu_5950_Recursive sequence

题意:递推求解:F(n) = 2*F(n-2) + F(n-1) + n和F(1) = a,F(2) = b;

题解:

一看数据范围,肯定矩阵加速递推,不过公式不是线性的,需要把公式转换为线性的公式

 #include<bits/stdc++.h>
#define F(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
typedef long long ll; const int mat_N=;
ll mo=; struct mat{
ll c[mat_N][mat_N];
void init(){memset(c,,sizeof(c));}
mat operator*(mat b){
mat M;int N=mat_N-;M.init();
F(i,,N)F(j,,N)F(k,,N)M.c[i][j]=(M.c[i][j]+c[i][k]*b.c[k][j])%mo;
return M;
}
mat operator^(ll k){
mat ans,M=(*this);int N=mat_N-;ans.init();
F(i,,N)ans.c[i][i]=;
while(k){if(k&)ans=ans*M;k>>=,M=M*M;}
return ans;
}
}A,B,C; int t,n,a,b; int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&n,&a,&b);
A=(mat){,,,,,,,
,,,,,,,
,,,,,,,
,,,,,,,
,,,,,,,
,,,,,,,
,,,,,,};
C=A^(n-);
ll ans=;
ans=(C.c[][]*a+C.c[][]*b+C.c[][]*+C.c[][]*+C.c[][]*+C.c[][]*+C.c[][])%mo;
printf("%lld\n",ans);
}
return ;
}

hdu_5950_Recursive sequence(矩阵快速幂)的更多相关文章

  1. HDU5950 Recursive sequence (矩阵快速幂加速递推) (2016ACM/ICPC亚洲赛区沈阳站 Problem C)

    题目链接:传送门 题目: Recursive sequence Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total ...

  2. HDU5950 Recursive sequence —— 矩阵快速幂

    题目链接:https://vjudge.net/problem/HDU-5950 Recursive sequence Time Limit: 2000/1000 MS (Java/Others)   ...

  3. hdu-5667 Sequence(矩阵快速幂+费马小定理+快速幂)

    题目链接: Sequence Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others) ...

  4. UVA - 10689 Yet another Number Sequence 矩阵快速幂

                      Yet another Number Sequence Let’s define another number sequence, given by the foll ...

  5. Yet Another Number Sequence——[矩阵快速幂]

    Description Everyone knows what the Fibonacci sequence is. This sequence can be defined by the recur ...

  6. HDU 1005 Number Sequence(矩阵快速幂,快速幂模板)

    Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1 ...

  7. HDU - 1005 Number Sequence 矩阵快速幂

    HDU - 1005 Number Sequence Problem Description A number sequence is defined as follows:f(1) = 1, f(2 ...

  8. HDU - 1005 -Number Sequence(矩阵快速幂系数变式)

    A number sequence is defined as follows:  f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) m ...

  9. 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 ...

随机推荐

  1. Selenium WebDriver多层表单切换

    [Java] 首先 测试网站frame结构为 -topframe: -centerframe: -leftframe: -mainframe: -bottomframe: 我当时遇到的问题是,首先在c ...

  2. CentOS6.5自带Python2.6.6升级至Python2.7

    CentOS6.5中Python2.6升级到Python2.7 由于Python开发团队已不再支持2.6版本,且该版本对一些软件不支持,因此将2.6升级到2.7. 1.安装Python2.7: 下载源 ...

  3. linux标准输入输出2>&1

    linux中有三种标准输入输出,分别是STDIN,STDOUT,STDERR,对应的数字是0,1,2.     STDIN是标准输入,默认从键盘读取信息:STDOUT是标准输出,默认将输出结果输出至终 ...

  4. 【ARM】S3C6410芯片的启动流程

    S3C6410芯片的启动流程 (1) 上电后首先运行iRom(BL0)内的代码,主要完成时钟和看门狗等外围器件的初始化.(2) 拷贝SD卡或者NnadFlash中的前4k(BL1)代码到片内ram(垫 ...

  5. Python基础知识学习_Day3

    一.字典用法 字典是一种key-value数据类型,通过key获取具体value的内容,字典的特性是无序.去重. 增删改查用法如下: 1.1基本增删改查操作 name = {"," ...

  6. HTML1高级

    HTML头部 一.链接在新窗口打开如果要定义整个网页的链接在新窗口打开,只要在/head里定义/base target="_blank"就可以了</p> 二.文档描述1 ...

  7. how to make a git repo un-git?

    If you have a git repo and now you want to make it a plain filesystem tree .. (removing the git trac ...

  8. kubernetes port nodePort targetPort 理解

    port The port that the service is exposed on the service's cluster ip (virsual ip). Port is the serv ...

  9. Topself 方便调试的Window服务框架

    Installing Topshelf nuget Install-Package Topshelf public class TownCrier { readonly Timer _timer; p ...

  10. lsof使用

    用netstat命令去统计服务器目前的网络连接状态 netstat -n|awk '/^tcp/{++S[$NF]}END{for(a in S) print a,S[a]}'   netstat - ...