题目链接

题意 :给你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. 调整Windows8允许多用户登录

    最近LP说要在继续教育平台上学习,好像是中级的需要进行继续教育吧,具体情况不管了.LP说网站登录后没办法听到声音看到视频,但是我的可以,系统环境是Win8,IE10,不过是在Chrome下使用IPA插 ...

  2. JAVA中RSS解析器(rome.jar和jdom.jar)范例

    1.需要 jdom.jar 和 rome.jar 这两个包.2.创建一个项目,web.xml的内容如下: 代码如下 复制代码 <?xml version="1.0" enco ...

  3. Java Thread UncaughtExceptionHandler

    有没有发生过这样的情况,你写的工作线程莫名其妙的挂了,如果不是被你刚好看到,拿只能抓瞎了,不知道啥原因了,因为异常的时候只会把stack trace打在控制台上,不会记在你想记得错误日志里,头皮都抓破 ...

  4. Eclipse插件checkstyle 代码风格的检查

    插件checkstyle 的安装 方法一:  1.Eclipse中,选择Help->Software Updates->Find and Install  2.选择 Search for ...

  5. Cocos2d-x使用UserDefault数据持久化实例:保存背景音乐和音效设置

    UserDefault可以实现数据的存储,但是它的使用不能泛滥,具体讲一般情况下不会使用它保存大量的数据,它没有SQL语句那样的灵活.UserDefault除了保存游戏设置外,还有可以长期保持游戏精灵 ...

  6. UEditor的使用方法

    文本编辑器程序员都会用到,今天无意中发现UEditor是个好东西,特奉献给大家,并提供下载. 这个编辑器的亮点是可以显示当前输入多少字符,还可以输入多少字符. 新创建的MVC项目,在layout页面里 ...

  7. (POJ 1797) Heavy Transportation 最大生成树

    题目链接:http://poj.org/problem?id=1797 Description Background Hugo Heavy is happy. After the breakdown ...

  8. js中的一些零碎方法

    ajax表单提交: $.post("do_login", f.serializeArray(), function(data) { if (data.status + " ...

  9. lex&yacc6 ---error

    类的检测 http://blog.csdn.net/pandaxcl/article/details/1536784

  10. 面向切面的Spring

    在软件开发中,发布于应用中多处的功能被称为横切关注点.通常,这些横切关注点从概念上是与应用的业务逻辑相分离的(但往往直接嵌入到应用的业务逻辑之中).将横切关注点与业务逻辑相分离是AOP所要解决的. 一 ...