矩阵相乘

代码如下:

 1 #include <cstdio>
 2 #include <cstring>
 3
 4 struct matrix
 5 {
 6     int g[10][10];
 7 }mt;
 8
 9 int kk,m;
10
11 matrix multi(matrix a,matrix b)
12 {
13     matrix ans;
14
15     for(int i = 0;i < 10;i ++)
16     {
17         for(int j = 0;j < 10;j ++)
18         {
19             int t = 0;
20             for(int u = 0;u < 10;u ++)
21             {
22                 t += a.g[i][u] * b.g[u][j];
23                 t = t % m;
24             }
25             ans.g[i][j] = t % m;
26         }
27     }
28
29     return ans;
30 }
31
32 int solve(int k)
33 {
34     matrix temp = mt;
35     matrix ans;
36     memset(ans.g,0,sizeof(ans.g));
37     for(int i = 0;i < 10;i ++)
38     {
39         ans.g[0][i] = i;
40     }
41
42     for(int i = 0;k != 0;i ++)
43     {
44         if(k & (1 << i))
45             ans = multi(ans,temp);
46         temp = multi(temp,temp);
47         k = k & (~(1 << i) );
48     }
49
50     return ans.g[0][9];
51 }
52
53 int main()
54 {
55     while(scanf("%d%d",&kk,&m) == 2)
56     {
57         memset(mt.g,0,sizeof(mt.g));
58         for(int i = 0;i < 10;i ++)
59         {
60             int a;
61             scanf("%d",&a);
62             mt.g[9 - i][9] = a;
63             if(i < 9)
64             mt.g[9 - i][8 - i] = 1;
65         }
66
67         if(kk < 10)
68         {
69             printf("%d\n",kk % m);
70             continue;
71         }
72
73         printf("%d\n",solve(kk-9)%m);
74     }
75
76     return 0;
77 }

转载于:https://www.cnblogs.com/Shirlies/archive/2012/05/25/2518633.html

hdu 1757【A Simple Math Problem】相关推荐

  1. HDU - 5974 A Simple Math Problem 题解

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

  2. Exponential distribution 指数分布【转自Math WiKi】

    Exponential distribution 指数分布[转自Math WiKi] 原文链接:http://math.wikia.com/wiki/Exponential_distribution ...

  3. FZYZ-2071 A Simple Math Problem IX

    P2071 -- A Simple Math Problem IX 时间限制:1000MS      内存限制:262144KB 状态:Accepted      标签:    数学问题-博弈论    ...

  4. A Simple Math Problem(2020 ICPC 江西省省赛)

    A Simple Math Problem ∑i=1n∑j=1if(j)[gcd(i,j)=1]∑i=1n∑j=inf(i)[gcd(i,j)=1]∑i=1n∑j=1nf(i)[gcd(i,j)=1] ...

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

  6. A Simple Math Problem题目翻译

    A Simple Math Problem | JXNUOJhttps://acs.jxnu.edu.cn/problem/ICPCJX2020A 描述: Huanhuan challenges yo ...

  7. 1.24A Simple Math Problem

    原网址:https://acs.jxnu.edu.cn/problem/NOIOPJCH02077215 描述: Huanhuan challenges you to a simple math pr ...

  8. Simple Math Problem

    Simple Math Problem | JXNUOJ 翻译: 描述: 通通又在玩数学游戏.她已经多次遇到这个方针了,所以不用说,她知道你说的是什么.现在她将这个问题推给你.你需要观察下面的方阵,然 ...

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

最新文章

  1. 循环神经网络实现文本情感分类之使用LSTM完成文本情感分类
  2. 计算机英语教学能力大赛,英语教学网络中心举办 “志勤杯”英语口语技能大赛 和“志勤杯”英语写作技能大赛...
  3. Python 中 xpath 语法 与 lxml 库解析 HTML/XML 和 CSS Selector
  4. MyCms自媒体内容管理系统 v1.6.0.1
  5. linux命令之awk终极系列
  6. gamma软件linux安装图示,[转载]linux下安装GAMMA软件
  7. 华为智慧屏鸿蒙20,华为智慧屏SE系列首销 搭载鸿蒙分布式跨屏技术
  8. 高分毕业论文答辩自述稿(附注意事项及模板)
  9. java前后端技术栈
  10. 关于加速度传感器方面内容汇总
  11. 详细讲解二极管的钳位电路和限幅电路
  12. 网络安全学习笔记——蓝队实战攻防
  13. JAVA程序设计-头歌实训-------# 第一阶段 Java语言快速入门
  14. javax异常: javax.imageio.IIOException: Can't create output stream解决方法
  15. html table文字竖,表格里的文字怎么竖排
  16. 视觉SLAM十四讲学习记录 第五讲
  17. 判断推理——类比推理
  18. C++:判断键盘输入的两个正整数是否为互质数
  19. 对口升学班计算机英语,对口升学计算机专业试题及对口升学英语模拟试卷.doc...
  20. JS 作用域和作用域链

热门文章

  1. Say Hello to Integers (Java)
  2. 软件与证书之间的关系
  3. 台式计算机wifi老掉线,电脑连接WiFi容易断线或速度慢怎么回事 教你怎么解决
  4. WebPack 学习:从阮神的15个DEMO开始
  5. 学习 stm32(TTL)串口通信控制16路舵机控制板(维特智能)
  6. R7900P/R7960P/R8000P梅林固件
  7. WPS 表格自适应图片
  8. 【python】必应api获取壁纸信息+修改桌面+倒计时显示
  9. 第13届景驰-埃森哲杯广东工业大学ACM程序设计大赛 G 旋转矩阵 【模拟】
  10. CVE-2018-1273漏洞复现日志+IDS规则编写