题意:略

简单的矩阵快速幂就行了

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define LL long long
#define N 10
int m;
struct node{
int mat[N][N];
node operator *(const node &x){
node tmp;
memset(tmp.mat,0,sizeof(tmp.mat));
for(int i=0;i<N;i++)
for(int j=0;j<N;j++)
for(int k=0;k<N;k++){
tmp.mat[i][j]+=(mat[i][k]*x.mat[k][j])%m;
tmp.mat[i][j]%=m;
}
return tmp;
}
}cat,b;
node _pow(int n){
int i;
memset(b.mat,0,sizeof(b.mat));
for(i=0;i<N;i++)
b.mat[i][i]=1;
while(n){
if(n&1)
b=b*cat;
cat=cat*cat;
n>>=1;
}
return b;
}
int main(int argc, char** argv) {
int sum,n;
int i,j; while(scanf("%d%d",&n,&m)!=EOF){
memset(cat.mat,0,sizeof(cat.mat));
for(i=0;i<N-1;i++)
cat.mat[i+1][i]=1;
for(i=0;i<N;i++)
scanf("%d",&cat.mat[0][i]);
if(n<N){
printf("%d\n",n%m);
continue;
}
sum=0;
cat=_pow(n-9);
for(i=0;i<N;i++)
sum+=cat.mat[0][i]*(9-i);
printf("%d\n",sum%m); }
return 0;
}

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(矩阵)

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

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

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

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

  5. 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) + …… ...

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

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

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

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

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

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

随机推荐

  1. VC断点不可用的问题

    文章一 今天我笔记本的VC编译器莫名其妙的就进入不了断点了,而台式机确是好的,问题是一进入调试,断点就自动被取消了,郁闷了一下午,无法进入断点的原因很多,都有想重装VC编译器的打算了,晚上回来查查资料 ...

  2. hdu1166 树状数组

    不知道为什么用C++输入输出死活不过,换成C的就过了... #include <stdio.h> #include <string.h> //================= ...

  3. 利用FreeMarker静态化网页

    1.介绍-FreeMarker是什么 模板引擎:一种基于模板的.用来生成输出文本的通用工具 基于Java的开发包和类库 2.介绍-FreeMarker能做什么 MVC框架中的View层组件 Html页 ...

  4. 两分钟让你明白cocos2dx的屏幕适配策略

    闲来无事,整理了一下cocos2dx的屏幕适配策略,本文适用于想快速理解cocos2dx适配的开发者. 我们先假设:以854 * 480 的屏幕为标准进行开发,当然,这也就是cocos2dx所说的设计 ...

  5. yarn状态机的可视化

    YARN为了实现多个状态机的对象,控制ResourceManager中间RMAppImpl.RMApp-AttemptImpl.RMContainerImpl和RMNodeImpl,NodeManag ...

  6. android——ObjectAnimator动画(一)

    直接贴上集中用法 package com.example.test; import com.example.test.views.CircleView; import android.animatio ...

  7. 查看IIS进程id

    Windows 2003 cscript C:\windows\system32\iisapp.vbs -a Windows 2008 C:\windows\system32\inetsrv\appc ...

  8. BeeswaxException 以及其他问题

    Could not read table BeeswaxException(handle=QueryHandle(log_context='ae18ae74-518f-400b-b4b0-d399ed ...

  9. win8下 web测试 之 hosts绑定

    从这个开始,开启web测试之旅 绑定hosts: 1.在C:\Windows\System32\drivers\etc下找到 hosts 文件 2.将hosts文件复制到一个地方: 3.修改hosts ...

  10. CMD下修改IP地址

    @echo off netsh interface ip set address name="本地连接" static 192.168.1.55 255.255.255.0 192 ...