题意:略

简单的矩阵快速幂就行了

#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. C语言的本质(36)——makefile基础

    除了Hello World这种极简单的程序之外,一般的程序都是由多个源文件编译链接而成的,这些源文件的处理步骤通常用Makefile来管理.makefile带来的好处就是--"自动化编译&q ...

  2. 2014.8.4我出的模拟赛【NTR酋长】

    NTR酋长 (ntr.pas/.c/.cpp) 黄巨大终于如愿以偿的进入了czy的后宫中……但是czy很生气……他要在黄巨大走到他面前的必经之路上放上几个NTR酋长来阻挡黄巨大. 众所周知,NTR酋长 ...

  3. bzoj1632 [Usaco2007 Feb]Lilypad Pond

    Description Farmer John 建造了一个美丽的池塘,用于让他的牛们审美和锻炼.这个长方形的池子被分割成了 M 行和 N 列( 1 ≤ M ≤ 30 ; 1 ≤ N ≤ 30 ) 正方 ...

  4. PKU 1050-To The Max(找矩形内元素最大和)

    Given a two-dimensional array of positive and negative integers, a sub-rectangle is any contiguous s ...

  5. LeeCode-Rotate Array

    Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array  ...

  6. 手动调整导航控制器中的viewcontroller

    NSMutableArray *array = [[NSMutableArray alloc]initWithArray: [self.navigationController viewControl ...

  7. [置顶] ID3算法的python实现

    这篇文章的内容接着http://blog.csdn.net/xueyunf/article/details/9214727的内容,所有还有部分函数在http://blog.csdn.net/xueyu ...

  8. Ffmpeg和SDL创建线程(转)

    Spawning Threads Overview Last time we added audio support by taking advantage of SDL's audio functi ...

  9. UVA 246 - 10-20-30 (模拟+STL)

    UVA 246 - 10-20-30 题目链接 题意:给52张的扑克堆,先从左往右发7张牌,之后连续不断从左往右发7张牌,假设有牌堆形成了下面3种情况(按顺序推断): 1.头两张+尾一张和为10或20 ...

  10. Javascript进阶篇——( JavaScript内置对象---上-Date,string,charAt,indexOf,split,substring,substr)笔记整理

    什么是对象JavaScript 中的所有事物都是对象,如:字符串.数值.数组.函数等,每个对象带有属性和方法.对象的属性:反映该对象某些特定的性质的,如:字符串的长度.图像的长宽等:对象的方法:能够在 ...