先贴四份矩阵快速幂的模板:http://www.cnblogs.com/shangyu/p/3620803.html

http://www.cppblog.com/acronix/archive/2010/08/23/124470.aspx?opt=admin

http://www.cnblogs.com/vongang/archive/2012/04/01/2429015.html

http://www.cnblogs.com/yan-boy/archive/2012/11/29/2795294.html

233 Matrix

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 257    Accepted Submission(s): 165

Problem Description
   In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23333, or 233333 ... in the same meaning. And here is the question: Suppose we have a matrix called 233 matrix. In the first line, it would be 233, 2333, 23333... (it means a0,1 = 233,a0,2 = 2333,a0,3 = 23333...) Besides, in 233 matrix, we got ai,j = ai-1,j +ai,j-1( i,j ≠ 0). Now you have known a1,0,a2,0,...,an,0, could you tell me an,m in the 233 matrix?
 
Input
   There are multiple test cases. Please process till EOF.
   For each case, the first line contains two postive integers n,m(n ≤ 10,m ≤ 109). The second line contains n integers, a1,0,a2,0,...,an,0(0 ≤ ai,0 < 231).
 
Output
   For each case, output an,m mod 10000007.
 
Sample Input
1 1
1
2 2
0 0
3 7
23 47 16
 
Sample Output
234
2799
72937

Hint

 
Source
 
Recommend
hujie   |   We have carefully selected several similar problems for you:  5017 5016 5014 5013 5012 

题解1:http://www.cnblogs.com/whatbeg/p/3971994.html

题解2:http://blog.csdn.net/u013368721/article/details/39271565

题目分析:矩阵快速幂,构建一个如下的矩阵即可:

  1. n+2行的矩阵
  2. --                      --   --  --
  3. | 1  1  1  1  1  1  1  0 |   | a1 |
  4. | 0  1  1  1  1  1  1  0 |   | a2 |
  5. | 0  0  1  1  1  1  1  0 |   | a3 |
  6. | 0  0  0  1  1  1  1  0 |   | a4 |
  7. | 0  0  0  0  1  1  1  0 | * | a5 |
  8. | 0  0  0  0  0  1  1  0 |   | an |
  9. |  - - - - - - - - - - - |   |    |
  10. | 0  0  0  0  0  0 10  1 |   | 233|
  11. | 0  0  0  0  0  0  0  1 |   | 3  |
  12. --                      --   --  --
  1. #include<iostream>
  2. #include<cstring>
  3. #include<cstdlib>
  4. #include<cstdio>
  5. #include<algorithm>
  6. #include<cmath>
  7. #include<queue>
  8. #include<map>
  9. #include<string>
  10.  
  11. #define N 15
  12. #define M 15
  13. #define mod 10000007
  14. #define p 10000007
  15. #define mod2 100000000
  16. #define ll long long
  17. #define LL long long
  18. #define maxi(a,b) (a)>(b)? (a) : (b)
  19. #define mini(a,b) (a)<(b)? (a) : (b)
  20.  
  21. using namespace std;
  22.  
  23. ll nn,m;
  24. ll n;
  25. ll x[];
  26. //ll ans;
  27.  
  28. struct Mat
  29. {
  30. ll mat[N][N];
  31. };
  32.  
  33. Mat e,f,g;
  34. Mat operator * (Mat a,Mat b)
  35. {
  36. Mat c;
  37. memset(c.mat,,sizeof(c.mat));
  38. ll i,j,k;
  39. for(k = ; k < n ; k++)
  40. {
  41. for(i = ; i < n ;i++)
  42. {
  43. if(a.mat[i][k]==) continue;//优化
  44. for(j = ;j < n ;j++)
  45. {
  46. if(b.mat[k][j]==) continue;//优化
  47. c.mat[i][j] = (c.mat[i][j]+(a.mat[i][k]*b.mat[k][j])%mod)%mod;
  48. }
  49. }
  50. }
  51. return c;
  52. }
  53. Mat operator ^(Mat a,ll k)
  54. {
  55. Mat c;
  56. ll i,j;
  57. for(i = ; i < n ;i++)
  58. for(j = ; j < n ;j++)
  59. c.mat[i][j] = (i==j);
  60. for(; k ;k >>= )
  61. {
  62. if(k&) c = c*a;
  63. a = a*a;
  64. }
  65. return c;
  66. }
  67.  
  68. void ini()
  69. {
  70. ll i,j;
  71. for(i=;i<=nn;i++){
  72. scanf("%I64d\n",&x[i]);
  73. }
  74. memset(e.mat,,sizeof(e.mat));
  75. memset(f.mat,,sizeof(f.mat));
  76. e.mat[][]=;
  77. e.mat[][]=;
  78. e.mat[][]=+x[];
  79. for(i=;i<=nn;i++){
  80. e.mat[][i+]=e.mat[][i]+x[i];
  81. }
  82. for(j=;j<nn+;j++){
  83. if(j!=){
  84. f.mat[][j]=;
  85. }
  86. f.mat[][j]=;
  87. }
  88. for(i=;i<nn+;i++){
  89. for(j=i;j<nn+;j++){
  90. f.mat[i][j]=;
  91. }
  92. }
  93. n=nn+;
  94. }
  95.  
  96. void solve()
  97. {
  98. if(m>){
  99. g= e* (f^(m-) );
  100. }
  101. else{
  102. g.mat[][nn+]=e.mat[][nn+];
  103. }
  104. }
  105.  
  106. void out()
  107. {
  108. printf("%I64d\n",g.mat[][nn+]);
  109. }
  110.  
  111. int main()
  112. {
  113. // freopen("data.in","r",stdin);
  114. // freopen("data.out","w",stdout);
  115. //scanf("%d",&T);
  116. //for(int cnt=1;cnt<=T;cnt++)
  117. // while(T--)
  118. while(scanf("%I64d%I64d",&nn,&m)!=EOF)
  119. {
  120. ini();
  121. solve();
  122. out();
  123. }
  124.  
  125. return ;
  126. }

HDU 5015 233 Matrix(网络赛1009) 矩阵快速幂的更多相关文章

  1. 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 Coin 矩阵快速幂

    Bob has a not even coin, every time he tosses the coin, the probability that the coin's front face u ...

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

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

  3. 题解报告:poj 3233 Matrix Power Series(矩阵快速幂)

    题目链接:http://poj.org/problem?id=3233 Description Given a n × n matrix A and a positive integer k, fin ...

  4. HDU - 5015 233 Matrix (矩阵快速幂)

    In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23333, or 233 ...

  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 5950 Recursive sequence 【递推+矩阵快速幂】 (2016ACM/ICPC亚洲区沈阳站)

    Recursive sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  7. 广工十四届校赛 count 矩阵快速幂

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6470 题意:求,直接矩阵快速幂得f(n)即可 构造矩阵如下: n^3是肯定得变换的,用二项式展开来一点 ...

  8. hdu 2604 Queuing dp找规律 然后矩阵快速幂。坑!!

    http://acm.hdu.edu.cn/showproblem.php?pid=2604 这题居然O(9 * L)的dp过不了,TLE,  更重要的是找出规律后,O(n)递推也过不了,TLE,一定 ...

  9. POJ 3233 Matrix Power Series (矩阵快速幂+二分求解)

    题意:求S=(A+A^2+A^3+...+A^k)%m的和 方法一:二分求解S=A+A^2+...+A^k若k为奇数:S=(A+A^2+...+A^(k/2))+A^(k/2)*(A+A^2+...+ ...

随机推荐

  1. 如何写好一个vue组件,老夫的一年经验全在这了【转】 v-bind="$attrs" 和 v-on="$listeners"

    如何写好一个vue组件,老夫的一年经验全在这了 一个适用性良好的组件,一种是可配置项很多,另一种就是容易覆写,从而扩展功能 Vue 组件的 API 来自三部分——prop.事件和插槽: prop 允许 ...

  2. 将Xcode的本地代码push到github仓库上

    1.首先,你得有一个github账号,如果没有的话就去注册一个,通过下面图片的方式创建一个github仓库. 2.创建仓库后填写相关的信息,比如说仓库名等. 3.在xcode上进行设置,添加远程git ...

  3. 导出Excel插件——Export-CSV ---20150610

    出处:http://bbs.hcharts.cn/thread-99-1-1.html   导出Excel插件——Export-CSV 一.插件信息 插件名:Export-CSV(导出Execl文件) ...

  4. 微信小程序 wx.request POST请求------中文乱码问题

    问题: 一个简单的表单,提交后台返回数据“提交成功”. 以为没问题了,但是没过多久后台小哥就问为啥那么多乱码,找了很久原因,发现在提交的时候就已经乱码了. 嗯,前端问题,然后测试GET/POST方法. ...

  5. centos7.2 安装nginx

    一.首先检查gcc编译器安装了没 二 首先安装必要的库(nginx 中gzip模块需要 zlib 库,rewrite模块需要 pcre 库,ssl 功能需要openssl库),检查一下是否已经安装了( ...

  6. python爬虫入门六:Selenium库

    在我们爬取网页过程中,经常发现我们想要获得的数据并不能简单的通过解析HTML代码获取,这些数据是通过AJAX异步加载方式或经过JS渲染后才呈现在页面上显示出来. selenuim是一种自动化测试工具, ...

  7. ACM训练联盟周赛 Teemo's formula

    Teemo has a formula and he want to calculate it quickly. The formula is . As the result may be very ...

  8. Memcached特性及优缺点

    为了加快文件访问速度且提供多个使用者.需要在内存中建立内存缓存数据的管理减小读写磁盘的次数及保证数据的更新.因为需要使用cache缓存.   1.Memcached 主要特性 a.数据仅存在于内存中, ...

  9. Java实现——Socket网络通信的机制以及实现举例

    1. 网络间的进程通信与Socket TCP/IP协议族中网络层的IP地址可以唯一标识网络中的主机,而传输层的协议+端口可以唯一标识主机中的应用程序(进程).这样利用这三元组就可以标识网络的进程了,网 ...

  10. jmx_exportter+prometheus+grafana监控hadoop

    0.介绍(摘录自https://www.hi-linux.com/posts/25047.html) 什么是Prometheus? Prometheus是由SoundCloud开发的开源监控报警系统和 ...