hdu_5950_Recursive sequence(矩阵快速幂)
题目链接:hdu_5950_Recursive sequence
题意:递推求解:F(n) = 2*F(n-2) + F(n-1) + n4 和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(矩阵快速幂)的更多相关文章
- HDU5950 Recursive sequence (矩阵快速幂加速递推) (2016ACM/ICPC亚洲赛区沈阳站 Problem C)
题目链接:传送门 题目: Recursive sequence Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total ...
- HDU5950 Recursive sequence —— 矩阵快速幂
题目链接:https://vjudge.net/problem/HDU-5950 Recursive sequence Time Limit: 2000/1000 MS (Java/Others) ...
- hdu-5667 Sequence(矩阵快速幂+费马小定理+快速幂)
题目链接: Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- UVA - 10689 Yet another Number Sequence 矩阵快速幂
Yet another Number Sequence Let’s define another number sequence, given by the foll ...
- Yet Another Number Sequence——[矩阵快速幂]
Description Everyone knows what the Fibonacci sequence is. This sequence can be defined by the recur ...
- 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 ...
- HDU - 1005 Number Sequence 矩阵快速幂
HDU - 1005 Number Sequence Problem Description A number sequence is defined as follows:f(1) = 1, f(2 ...
- 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 ...
- 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 ...
随机推荐
- python 数据聚合与分组
前面讲完了字符处理,但对数据进行整体性的聚合运算以及分组操作也是数据分析的重要内容. 通过数据的聚合与分组,我们能更容易的发现隐藏在数据中的规律. 数据分组 数据的分组核心思想是:拆分-组织-合并 首 ...
- Kali
http://zydhacker.blog.163.com/blog/static/211795073201447337920/
- LED :制作一个追逐序列(霹雳游侠)
; ,,}; ; void setup() { ; led<NbrLeds; led++){ pinMode(ledPins[led], OUTPUT); } } void loop() { ; ...
- Linux 分区挂载方案
/boot 1G swap 2G(看内存决定) / 10-15G /home 5G
- Html5移动端页面自适应百分比布局
按百分比布局,精度肯定不会有rem精确 <!DOCTYPE html> <html lang="en"> <head> <meta cha ...
- extjs+amcharts生成3D柱状图和数据表格使用总结
废话不多说,使用extjs+amcharts创建3d柱状图和数据表实例,如下: 1.首先定义一个数据模型 Ext.define("cacheHijack", { extend : ...
- 51nod1092(lcs简单运用/dp)
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1092 题意:中文题诶- 思路: 解法1:最坏的情况就是在原字 ...
- KMP算法 学习例题 POJ 3461Oulipo
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37971 Accepted: 15286 Description The ...
- 网络爬虫-获取infoq里的测试新闻保存至html
用java+webdriver+testng实现获取infoq里的测试新闻,获取文章标题和内容,保存至html文件 前提条件: 已安装好java环境,工程导入了webdriver的jar包和testn ...
- PHP学习资源
PHPerNote PHPerNote 是一个php程序员的工作生活笔记,本站包含了php网络编程学习教程,数据库(主要是MySQL数据库)教程,javascript,jquery,div+css,h ...