hdu------(1757)A Simple Math Problem(简单矩阵快速幂)
A Simple Math Problem
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2791 Accepted Submission(s): 1659
If x < 10 f(x) = x.
If x >= 10 f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + …… + a9 * f(x-10);
And ai(0<=i<=9) can only be 0 or 1 .
Now, I will give a0 ~ a9 and two positive integers k and m ,and could you help Lele to caculate f(k)%m.
In each case, there will be two lines.
In the first line , there are two positive integers k and m. ( k<2*10^9 , m < 10^5 )
In the second line , there are ten integers represent a0 ~ a9.
1 1 1 1 1 1 1 1 1 1
20 500
1 0 1 0 1 0 1 0 1 0
104
//#define LOCAL
#include<cstdio>
#include<cstring>
#define LL __int64
using namespace std;
const int maxn=;
LL k,m;
int aa[maxn],mat[maxn][maxn];
int ans[maxn][maxn]; void init()
{
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
if(i==)
mat[i][j]=aa[j];
else
if(i==j+)mat[i][j]=;
else mat[i][j]=;
if(i==j)
ans[i][j]=;
else ans[i][j]=;
}
}
} void Matrix(int a[][],int b[][])
{ int c[][];
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
c[i][j]=;
for(int k=;k<;k++)
{
c[i][j]=(c[i][j]+a[i][k]*b[k][j])%m;
}
}
}
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
a[i][j]=c[i][j];
}
}
} void pow(LL n)
{
while(n>)
{
if(n&) Matrix(ans,mat);
n>>=1L;
if(n==)break;
Matrix(mat,mat);
}
} int main()
{
#ifdef LOCAL
freopen("test.in","r",stdin);
#endif while(scanf("%I64d%I64d",&k,&m)!=EOF)
{
for(int i=;i<;i++)
scanf("%d",aa+i);
if(k<) printf("%I64d\n",k%m);
else
{
init();
pow(k-);
int res=;
for(int i=;i<;i++)
res=(res+(-i-)*ans[][i])%m;
printf("%d\n",res);
}
}
return ;
}
hdu------(1757)A Simple Math Problem(简单矩阵快速幂)的更多相关文章
- hdu 1757 A Simple Math Problem (矩阵快速幂,简单)
题目 也是和LightOJ 1096 和LightOJ 1065 差不多的简单题目. #include<stdio.h> #include<string.h> #include ...
- HDU 1757 A Simple Math Problem(矩阵快速幂)
题目链接 题意 :给你m和k, 让你求f(k)%m.如果k<10,f(k) = k,否则 f(k) = a0 * f(k-1) + a1 * f(k-2) + a2 * f(k-3) + …… ...
- hdu 1757 A Simple Math Problem (矩阵快速幂)
Description Lele now is thinking about a simple function f(x). If x < 10 f(x) = x. If x >= 10 ...
- HDU 1757 A Simple Math Problem( 矩阵快速幂 )
<font color = red , size = '4'>下列图表转载自 efreet 链接:传送门 题意:给出递推关系,求 f(k) % m 的值, 思路: 因为 k<2 * ...
- hdu 1757 A Simple Math Problem(矩阵快速幂乘法)
Problem Description Lele now is thinking about a simple function f(x). If x < f(x) = x. If x > ...
- HDU 1757 A Simple Math Problem(矩阵快速幂模板)
题意:题意很简单,不多说了. 思路: |f(10) | |a0 a1 a2 ...a8 a9| |f(9)|| f(9) | | 1 0 0 ... 0 ...
- HDU 1757 A Simple Math Problem(矩阵高速幂)
题目地址:HDU 1757 最终会构造矩阵了.事实上也不难,仅仅怪自己笨..= =! f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + -- + a9 ...
- hdu 1757 A Simple Math Problem (矩阵高速幂)
和这一题构造的矩阵的方法同样. 须要注意的是.题目中a0~a9 与矩阵相乘的顺序. #include <iostream> #include <cstdio> #include ...
- HDU1757-A Simple Math Problem,矩阵快速幂,构造矩阵水过
A Simple Math Problem 一个矩阵快速幂水题,关键在于如何构造矩阵.做过一些很裸的矩阵快速幂,比如斐波那契的变形,这个题就类似那种构造.比赛的时候手残把矩阵相乘的一个j写成了i,调试 ...
随机推荐
- bootstrp水平表单格式
1:form里添加类 "form-horizontal" 2:把标签和表单控件(input 等)放在一个带有类名 "form-group"的div里 3:标签可 ...
- HTTP协议:header标头说明
原文地址 http://blog.chinaunix.net/uid-7374279-id-4518834.html Header 解释 示例 Accept-Ranges 表明服务器是否支持指定范 ...
- WebRTC的学习(二)
英文原文的链接地址为:https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API/Overview WebRTC是由一些关联的API和协议一 ...
- [SAP ABAP开发技术总结]字符编码与解码、Unicode
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- onclick事件分析
有些时候,我们想实现这样的一种效果: <a href="imgs/2.jpg" title="A fireworks display" onc ...
- 百度翻译word-wrap,页面错乱原因查找过程(已修复)
今天群里有人发问, 进入百度翻译http://fanyi.baidu.com/#auto/zh/, 输入word-wrap,发现页面错乱. 寻找错乱原因. 上图 开始查找原因: 1.从请求入手 从ch ...
- 让你快速搭建一个bootstrap页面
<!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...
- 基础4 Android基础
基础4 Android基础 1. Activity与Fragment的生命周期. Activity生命周期 打开应用 onCreate()->onStart()->onResume 按BA ...
- iOS开发之 Xcode svn更新代码后,不能打开.xcodeproj,因为该项目文件不能被解析
http://www.cfanz.cn/?c=article&a=read&id=41565 解决方法: 1.对.xcodeproj 文件右键,显示包内容 2.双击打开 proj ...
- hdu 5317 RGCDQ(前缀和)
题目链接:hdu 5317 这题看数据量就知道需要先预处理,然后对每个询问都需要在 O(logn) 以下的复杂度求出,由数学规律可以推出 1 <= F(x) <= 7,所以对每组(L, R ...