题目链接

题意 :给你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. JavaScript高级程序开发3笔记

      Js对象 注意:js基本数据类型不是对象,但是"abc".match()这种,可以调用对象的方法,是因为调用方法是临时产生了一个wrapper的包装对象,this指向它: Js ...

  2. blazeDS集成spring的remote访问

     欢迎交流转载,请注明出处:http://www.cnblogs.com/shizhongtao/p/3490037.html 上一篇我只是简单实用blazeds创建了一个实例,大多数开发中,都是结合 ...

  3. NOIP2011(提高组)DAY2---观光公交(vijosP1741)

    描述 风景迷人的小城Y市,拥有n个美丽的景点.由于慕名而来的游客越来越多,Y市特意安排了一辆观光公交车,为游客提供更便捷的交通服务.观光公交车在第0分钟出现在1号景点,随后依次前往2.3.4……n号景 ...

  4. poj 3614 Sunscreen

                                                                                                        ...

  5. Git初始化与上传

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

  6. jquery实现抽奖转盘

    用jquery通过配置参数实现抽奖转盘 1.html代码 <!DOCTYPE html> <html lang="zh-CN"> <head> ...

  7. 微软有完善的WP开发教程

    微软的Windows Phone 开发者中心 地址:http://dev.windowsphone.com/zh-cn/develop由于这里的教程非常完善,大家直要把开发者中心的内容看完就可以了,所 ...

  8. Geographic Coordinate Systems

    Coordinate Systems Geographic Coordinate Systems This is an archive of a previous version of the Arc ...

  9. android eclipse集成环境

    Android开发工具(ADT)是一个插件为Eclipse IDE,它的目的是给你一个强大的,集成的环境来构建Android应用程序. ADT扩展了Eclipse的功能使用Android SDK工具, ...

  10. foxtable使用笔记

    1.设置关联表窗口的列的顺序:Tables("award.people").SetColVisibleWidth("name|100|sex|100|job|100|ag ...