UVa 10870 - Recurrences
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1811
矩阵快速幂
代码:
- #include<iostream>
- #include<cstdio>
- #include<string>
- #include<cstring>
- #include<cmath>
- #include<set>
- #include<map>
- #include<stack>
- #include<vector>
- #include<algorithm>
- #include<queue>
- #include<stdexcept>
- #include<bitset>
- #include<cassert>
- #include<deque>
- using namespace std;
- typedef long long ll;
- typedef unsigned int uint;
- const double eps=1e-12;
- const int INF=0x3f3f3f3f;
- const int N=50;
- ll ma[N][N],mb[N][N],mc[N][N];
- void matrixMul(ll a[][N],ll b[][N],int n,int m,int k,ll MOD)
- {
- memset(mc,0,sizeof(mc));
- for(int i=1;i<=n;++i)
- for(int j=1;j<=k;++j)
- for(int l=1;l<=m;++l)
- mc[i][j]=(mc[i][j]+a[i][l]*b[l][j]%MOD)%MOD;
- for(int i=1;i<=n;++i)
- for(int j=1;j<=m;++j)
- a[i][j]=mc[i][j];
- }
- int main()
- {
- //freopen("data.in","r",stdin);
- int d,n;
- ll m;
- while(cin>>d>>n>>m)
- {
- if(!d&&!n&&!m) break;
- memset(mb,0,sizeof(mb));
- for(int i=1;i<=d;++i)
- cin>>mb[i][1];
- for(int i=2;i<=d;++i)
- mb[i-1][i]=1;
- for(int i=d;i>=1;--i)
- cin>>ma[1][i];
- if(n<=d)
- {
- cout<<ma[1][d+1-n]<<endl;
- continue;
- }
- n-=d;
- while(n)
- {
- if((n&1))
- matrixMul(ma,mb,1,d,d,m);
- n=n>>1;
- matrixMul(mb,mb,d,d,d,m);
- }
- cout<<ma[1][1]<<endl;
- }
- return 0;
- }
UVa 10870 - Recurrences的更多相关文章
- UVA 10870 - Recurrences(矩阵高速功率)
UVA 10870 - Recurrences 题目链接 题意:f(n) = a1 f(n - 1) + a2 f(n - 2) + a3 f(n - 3) + ... + ad f(n - d), ...
- 矩阵快速幂 UVA 10870 Recurrences
题目传送门 题意:f(n) = a1f(n − 1) + a2f(n − 2) + a3f(n − 3) + . . . + adf(n − d), for n > d,求f (n) % m.训 ...
- UVA 10870 Recurrences(矩阵乘法)
题意 求解递推式 \(f(n)=a_1*f(n-1)+a_2*f(n-2)+....+a_d*f(n-d)\) 的第 \(n\) 项模以 \(m\). \(1 \leq n \leq 2^{31}-1 ...
- UVa 10870 Recurrences (矩阵快速幂)
题意:给定 d , n , m (1<=d<=15,1<=n<=2^31-1,1<=m<=46340).a1 , a2 ..... ad.f(1), f(2) .. ...
- UVA - 10870 Recurrences 【矩阵快速幂】
题目链接 https://odzkskevi.qnssl.com/d474b5dd1cebae1d617e6c48f5aca598?v=1524578553 题意 给出一个表达式 算法 f(n) 思路 ...
- UVa 10870 (矩阵快速幂) Recurrences
给出一个d阶线性递推关系,求f(n) mod m的值. , 求出An-dv0,该向量的最后一个元素就是所求. #include <iostream> #include <cstdio ...
- Recurrences UVA - 10870 (斐波拉契的一般形式推广)
题意:f(n) = a1f(n−1) + a2f(n−2) + a3f(n−3) + ... + adf(n−d), 计算这个f(n) 最重要的是推出矩阵. #include<cstdio> ...
- uva 10870 递推关系矩阵快速幂模
Recurrences Input: standard input Output: standard output Consider recurrent functions of the follow ...
- UVA - 10870 UVA - 10870
Problem ARecurrencesInput: standard inputOutput: standard output Consider recurrent functions of the ...
随机推荐
- js object(对象)
http://www.cnblogs.com/pingchuanxin/p/5773326.html Object(对象)是在所有的编程语言中都十分重要的一个概念,对于事物我们可以把他们看作是一个对象 ...
- golang时间
//获取本地location toBeCharge := "2015-01-01 00:00:00" //待转化为时间戳的字符串 注意 这里的小时和分钟还要秒必须写 因为是跟着模板 ...
- easyui 进度条
进度条创建 $.messager.progress({ title:'请稍后', msg:'正在努力...' }); 进度条关闭 $.messager.progress('close'); 弹窗对话框 ...
- ZendStudio的配置导出
File(文件)->Export(导 出),再弹出Export窗口中点击"General(常规)",选择"Preferences(首选项)" 点击&quo ...
- openfire升级指南
原文:http://www.liuhaihua.cn/archives/355.html 升级Openfire是和从头开始安装Openfire几乎一样简单.作为升级过程的一部分,它强烈建议您先备份当前 ...
- c++ char * const p问题
事实上这个概念谁都有,只是三种声明方式非常相似很容易记混. Bjarne在他的The C++ Programming Language里面给出过一个助记的方法: 把一个声明从右向左读. char * ...
- 记录---base64
什么是Base64呢? Base64是网络上最常见的用于传输8Bit字节代码的编码方式之一,大家可以查看RFC2045-RFC2049,上面有MIME的详细规范.Base64编码可用于在HTTP环境下 ...
- Css_Backgroud-position(背景图片)定位问题详解
background-position的说明: 设置或检索对象的背景图像位置.必须先指定 background-image 属性.该属性定位不受对象的补丁属性( padding )设置影响. ...
- mysql 保留两位小数
mysql保留字段小数点后两位小数用函数:truncate(s.price,2)即可.如果想用四舍五入的话用round(s.price,2).
- VC++编译GSL
目录 第1章 VC++ 1 1.1 修改行结束符 1 1.2 修改#include "*.c" 为 #include "*.inl" 2 1. ...