题目链接

题意 :给你m和k, 让你求f(k)%m。如果k<10,f(k) = k,否则 f(k) = a0 * f(k-1) + a1 * f(k-2) + a2 * f(k-3) + …… + a9 * f(k-10);
思路 :先具体介绍一下矩阵快速幂吧,刚好刚刚整理了网上的资料。可以先了解一下这个是干嘛的,怎么用。

这个怎么弄出来的我就不说了,直接看链接吧,这实在不是我强项,点这儿这儿也行

 //HDU 1757
#include <iostream>
#include <stdio.h> using namespace std; struct matrix
{
int m[][] ;
} b,tp,res,init ; int n,m ; matrix Mul(matrix a,matrix b)
{
matrix c ;
for(int i = ; i < ; i++)
{
for(int j = ; j < ; j++)
{
c.m[i][j] = ;
for(int k = ; k < ; k++)
{
c.m[i][j] += (a.m[i][k] * b.m[k][j]) % m ;
c.m[i][j] %= m ;
}
}
}
return c ;
} matrix matrix_mi(matrix p,int k)
{
matrix t = res;
for(int i = ; i <= ; i++) t.m[i][i] = ;
while(k)
{
if(k & )
t = Mul(t,p) ;
k >>= ;
p = Mul(p,p) ;
}
return t ;
} void Init()
{
for(int i = ; i < ; i++)
for(int j = ; j < ; j++)
if(i- == j)
init.m[i][j]=;
else
init.m[i][j]=;
}
int main()
{
Init() ;
while(~scanf("%d %d",&n,&m))
{
b = init ;
for(int i = ; i < ; i++)
scanf("%d",&b.m[][i]) ;
for(int i = ; i < ; i++)
for(int j = ; j < ; j++)
if(i==j)
res.m[i][j] = ;
else
res.m[i][j] = ;
if(n >= )
{
int sum = ;
tp = matrix_mi(b,n-) ;
for(int i = ; i < ; i++)
sum += (tp.m[][i] * (-i))%m ;
printf("%d\n",sum%m) ;
}
else printf("%d\n",n%m) ;
}
return ;
}

HDU 1757 A Simple Math Problem(矩阵快速幂)的更多相关文章

  1. HDU 1757 A Simple Math Problem (矩阵快速幂)

    题目 A Simple Math Problem 解析 矩阵快速幂模板题 构造矩阵 \[\begin{bmatrix}a_0&a_1&a_2&a_3&a_4&a ...

  2. hdu 1757 A Simple Math Problem_矩阵快速幂

    题意:略 简单的矩阵快速幂就行了 #include <iostream> #include <cstdio> #include <cstring> using na ...

  3. HDU 1757 A Simple Math Problem(矩阵)

    A Simple Math Problem [题目链接]A Simple Math Problem [题目类型]矩阵快速幂 &题解: 这是一个模板题,也算是入门了吧. 推荐一个博客:点这里 跟 ...

  4. HDU1757 A Simple Math Problem 矩阵快速幂

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  5. A Simple Math Problem(矩阵快速幂)----------------------蓝桥备战系列

    Lele now is thinking about a simple function f(x).  If x < 10 f(x) = x.  If x >= 10 f(x) = a0 ...

  6. HDU 1757 A Simple Math Problem 【矩阵经典7 构造矩阵递推式】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=1757 A Simple Math Problem Time Limit: 3000/1000 MS (J ...

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

  8. hdu 1757 A Simple Math Problem (矩阵快速幂,简单)

    题目 也是和LightOJ 1096 和LightOJ 1065 差不多的简单题目. #include<stdio.h> #include<string.h> #include ...

  9. HDU 1757 A Simple Math Problem( 矩阵快速幂 )

    <font color = red , size = '4'>下列图表转载自 efreet 链接:传送门 题意:给出递推关系,求 f(k) % m 的值, 思路: 因为 k<2 * ...

随机推荐

  1. MSSQL 数字钱转化为大写

    --说明: --1.本函数范围从 毫 ~ 兆 --2.有四种精度(元,角 ,分,厘 ,毫) --3.有三种进位规则(四舍五入,接舍去,非0就入) --参数说明:dbo.MoneyToCapital( ...

  2. 【知识分享】UIButton setTitle 设置为空 失效

    今天开发练习超级猜图,但是碰到了一个奇怪的问题 困扰我一个晚上,低效的夜晚 可恨~ 示例说明1 [button setTitle:@"" forState:UIControlSta ...

  3. (转)印度建全球最大生物识别数据库,MongoDB安全受质疑

    受棱镜门影响,各界对Aadhar的质疑从是否将威胁人民隐私与安全,转而聚焦在 Aadhar 搜集.储存以及处理资料的方法,以及美国新创公司 MongoDB 在计划中扮演的角色. 泱泱大国印度一直以来都 ...

  4. 在String()构造器不存在的情况下自定义一个MyString()函数,实现如下内建String()方法和属性:

    在String()构造器不存在的情况下自定义一个MyString()函数,实现如下内建String()方法和属性: var s = new MyString("hello"); s ...

  5. javascript 中的 call

    Javascript中call的使用 Javascript中call的使用自己感觉蛮纠结的,根据文档很好理解,其实很难确定你是否真正的理解. call 方法应用于:Function 对象调用一个对象的 ...

  6. 快速搭建MongoDB分布式集群

    目录Outline 1. prerequisites 2. steps to follow3. configuring the cluster4. a little test to see 1. Pr ...

  7. Git初始化与上传

    一: 现在git上Create个repository 二:进入要长传的工程目录打开git bash git initgit statusgit add .//add .的时候文件不要被占用. git ...

  8. Poj 2586 / OpenJudge 2586 Y2K Accounting Bug

    1.Link: http://poj.org/problem?id=2586 2.Content: Y2K Accounting Bug Time Limit: 1000MS   Memory Lim ...

  9. MVC3 ViewBage 输出的值 被编码

    问题描述:       后台,Actoin中我向ViewBage中加入了一个json ViewBage.JsonDateMenu ="[{\"id\":2,\" ...

  10. Get code int value for different encoding

    http://msdn.microsoft.com/en-us/library/system.text.encodinginfo.getencoding%28v=vs.110%29.aspx usin ...