题目链接:点击查看

题目大意:实现公式:

  1. f(x)=x,x<10
  2. f(x)=a0*f(x-1)+a1*f(x-2)+……+a9*f(x-10)

题目给出a0~a9,一个n和一个m,要求输出f(n)对m取模后的结果

题目分析:水题

初始矩阵:(取n=10即可)

f(n-1) f(n-2) f(n-3) f(n-4) f(n-5) f(n-6) f(n-7) f(n-8) f(n-9) f(n-10)

辅助矩阵:

a0 1 0 0 0 0 0 0 0 0
a1 0 1 0 0 0 0 0 0 0
a2 0 0 1 0 0 0 0 0 0
a3 0 0 0 1 0 0 0 0 0
a4 0 0 0 0 1 0 0 0 0
a5 0 0 0 0 0 1 0 0 0
a6 0 0 0 0 0 0 1 0 0
a7 0 0 0 0 0 0 0 1 0
a8 0 0 0 0 0 0 0 0 1
a9 0 0 0 0 0 0 0 0 0

答案矩阵:

f(n) f(n-1) f(n-2) f(n-3) f(n-4) f(n-5) f(n-6) f(n-7) f(n-8) f(n-9)

套模板即可,上代码:

#include<iostream>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cctype>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<set>
#include<map>
#include<sstream>
#define Pi acos(-1.0)
using namespace std;typedef long long LL;const int inf=0x3f3f3f3f;int mod;const int N=10;struct Ma
{LL a[N][N];Ma(){memset(a,0,sizeof(a));}friend Ma operator*(const Ma& a,const Ma& b){Ma ans;for(int i=0;i<N;i++)for(int j=0;j<N;j++){ans.a[i][j]=0;for(int k=0;k<N;k++){ans.a[i][j]=(ans.a[i][j]+a.a[i][k]*b.a[k][j]%mod)%mod;}}return ans;}
};Ma q_pow(Ma a,LL b)
{Ma ans;for(int i=0;i<N;i++)ans.a[i][i]=1;while(b){if(b&1)ans=ans*a;a=a*a;b>>=1;}return ans;
}int main()
{
//  freopen("input.txt","r",stdin);int n;while(scanf("%d%d",&n,&mod)!=EOF){Ma ans;for(int i=0;i<10;i++)scanf("%d",&ans.a[i][0]);for(int i=0;i<9;i++)ans.a[i][i+1]=1;if(n<10){printf("%d\n",n%mod);continue;}Ma st;for(int i=0;i<10;i++)st.a[0][i]=9-i;ans=q_pow(ans,n-9);printf("%lld\n",(st*ans).a[0][0]);}return 0;
}

HDU - 1757 A Simple Math Problem(矩阵快速幂,水题)相关推荐

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

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1757 在吴神的帮助下才明白如何构造矩阵,还是好弱啊. 此处盗一张图 1 #include <io ...

  2. 43行代码AC——HDU 1757 A Simple Math Problem(矩阵快速幂,附快速幂讲解)

    一道经典的矩阵快速幂模板题. 传送门1-->快速幂基本思想 传送门2-->矩阵快速幂讲解(教主传授) 代码(去掉空行43行) #include<iostream> #inclu ...

  3. 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) + -- ...

  4. hdu 1757 A Simple Math Problem 构造矩阵

    题意:函数f(x), 若 x < 10 f(x) = x. 若 x >= 10 f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + -- + ...

  5. HDU 1757 A Simple Math Problem

    Problem Description Lele now is thinking about a simple function f(x). If x < 10 f(x) = x. If x & ...

  6. HDU - 1757 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 * ...

  7. HDU - 5974 A Simple Math Problem 题解

    D - Simple Math Problem 戳上方进入原题哟~ 题目大意 给一个数 a,b. 让你求满足一下条件的 X,Y: X+Y = a LCM(X,Y) = b 解析 题目给出时间限制1s, ...

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

    2018-5-24 简单的矩阵快速幂问题,重点是如何找到对应关系. f(10) a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 f(9) f(9) 1 0 0 0 0 0 0 0 0 0 ...

  9. A Simple Math Problem 矩阵打水题

    A Simple Math Problem Lele now is thinking about a simple function f(x). If x < 10 f(x) = x. If x ...

最新文章

  1. iOS开发UI篇—CALayer简介
  2. 封装JDBC事务操作,执行存储过程测试
  3. centos配置ntp时间同步_Linux CentOS配置ntpd时间同步
  4. 最新数据显示,全国有580万人被限制乘坐高铁,大家怎么看?
  5. android user版本默认开启调试模式
  6. linux htb 源代码,LINUX TC:HTB相关源码
  7. linux系统date s使用,简述Linux下date命令的使用方法与实例
  8. 先天性脑部发育异常_儿童脑发育不良的3大“诱因”,若孩子出现这5种异常,要警惕...
  9. Marriage Match III HDU - 3277(二分权值 + 拆点 建边)
  10. Machine Learning - XI. Machine Learning System Design机器学习系统设计(Week 6)系统评估标准
  11. 【操作系统】银行家算法
  12. php原始 实现双向队列,用PHP实现一个双向队列
  13. linux查找文件并显示修改时间,linux下find命令和文件的三种时间
  14. win10 cannot open clipboard 解决办法
  15. 西门子g120变频器接线图_西门子G120变频器怎么样?好用吗?
  16. java 继承的写法_Java 类的继承详解
  17. 使用PowerShell查看Windows 补丁记录并写入数据库
  18. hypervisor详解
  19. 一本书读懂大数据 读书笔记(1)
  20. matlab的setup阶跃曲线图,matlab 绘制系统的单位阶跃响应曲线 并编写程序求峰值时间 超调量 | 学步园...

热门文章

  1. Spring什么是复杂对象
  2. leader选举的源码分析-Messenger
  3. 绕过网关访问图片上传并解决跨域问题
  4. Zuul:路由和高可用小结
  5. SpringBoot高级-消息-JMSAMQP简介
  6. redis(22)--二进制位数组
  7. java kafka client_Kafka Java Client基本使用及整合SpringBoot
  8. python实现一个商品管理_python编写商品管理
  9. 边缘计算架构_更灵活的自动化系统架构、通信和编程——在自动化领域部署边缘计算...
  10. Redis持久化方式的选择