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 a 0,1 = 233,a 0,2 = 2333,a 0,3 = 23333...) Besides, in 233 matrix, we got ai,j = a i-1,j +a i,j-1( i,j ≠ 0). Now you have known a 1,0,a 2,0,...,a n,0, could you tell me a n,m in the 233 matrix?

InputThere are multiple test cases. Please process till EOF.

For each case, the first line contains two postive integers n,m(n ≤ 10,m ≤ 10 9). The second line contains n integers, a 1,0,a 2,0,...,a n,0(0 ≤ a i,0 < 2 31).OutputFor each case, output a n,m mod 10000007.Sample Input

  1. 1 1
  2. 1
  3. 2 2
  4. 0 0
  5. 3 7
  6. 23 47 16

Sample Output

  1. 234
  2. 2799
  3. 72937
  4.  
  5. 题意:
    a[i][j]=a[i-1][j]+a[i][j-1];
    a[0][1]=233,a[0][2]=2333,a[0][3]=23333,......
    a[1][0]到a[n][0]由输入给出,求a[n][m];
  1. 思路:
    本来打算直接用a[i][j]=a[i-1][j]+a[i][j-1]作为公式进行推导,发现并不可行。
    实际上是直接对每一列进行操作。
    写完这题,大概矩阵快速幂才是真的入门。

  1. #include<iostream>
  2. #include<algorithm>
  3. #include<vector>
  4. #include<stack>
  5. #include<queue>
  6. #include<map>
  7. #include<set>
  8. #include<cstdio>
  9. #include<cstring>
  10. #include<cmath>
  11. #include<ctime>
  12. #define fuck(x) cout<<#x<<" = "<<x<<endl;
  13. #define debug(a,i) cout<<#a<<"["<<i<<"] = "<<a[i]<<endl;
  14. #define ls (t<<1)
  15. #define rs ((t<<1)+1)
  16. using namespace std;
  17. typedef long long ll;
  18. typedef unsigned long long ull;
  19. const int maxn = ;
  20. const int maxm = ;
  21. const int inf = 2.1e9;
  22. const ll Inf = ;
  23. const int mod = ;
  24. const double eps = 1e-;
  25. const double pi = acos(-);
  26.  
  27. ll num[];
  28.  
  29. struct Matrix{
  30. ll mp[][];
  31. };
  32. Matrix mul(Matrix a,Matrix b,int n){
  33. Matrix ans;
  34. for(int i=;i<=n;i++){
  35. for(int j=;j<=n;j++){
  36. ans.mp[i][j]=;
  37. for(int k=;k<=n;k++){
  38. ans.mp[i][j]+=a.mp[i][k]*b.mp[k][j];
  39. }
  40. ans.mp[i][j]%=mod;
  41. }
  42. }
  43. return ans;
  44. }
  45.  
  46. Matrix q_pow(Matrix a,int b,int n){
  47. Matrix ans;
  48. memset(ans.mp,,sizeof(ans.mp));
  49. for(int i=;i<=n;i++){
  50. ans.mp[i][i]=;
  51. }
  52. while (b){
  53. if(b&){
  54. ans=mul(ans,a,n);
  55. }
  56. b>>=;
  57. a=mul(a,a,n);
  58. }
  59. return ans;
  60. }
  61.  
  62. int main()
  63. {
  64. // ios::sync_with_stdio(false);
  65. // freopen("in.txt","r",stdin);
  66.  
  67. int n,m;
  68. while(scanf("%d%d",&n,&m)!=EOF){
  69. for(int i=;i<=n;i++){
  70. scanf("%lld",&num[i]);
  71. }
  72. Matrix exa;
  73. memset(exa.mp,,sizeof(exa.mp));
  74. int t=;
  75. exa.mp[n+][n+]=;
  76. for(int i=;i<=n+;i++){
  77. exa.mp[i][]=;exa.mp[i][n+]=;
  78. for(int j=;j<=t;j++){
  79. exa.mp[i][j+]=;
  80. }
  81. t++;
  82. }
  83. exa=q_pow(exa,m,n+);
  84. ll ans=;
  85. num[]=;num[n+]=;
  86. for(int i=;i<=n+;i++){
  87. ans+=exa.mp[n+][i]*num[i-];
  88. ans%=mod;
  89. }
  90. printf("%lld\n",ans);
  91.  
  92. }
  93.  
  94. return ;
  95. }

HDU - 5015 233 Matrix (矩阵快速幂)的更多相关文章

  1. HDU 5015 233 Matrix --矩阵快速幂

    题意:给出矩阵的第0行(233,2333,23333,...)和第0列a1,a2,...an(n<=10,m<=10^9),给出式子: A[i][j] = A[i-1][j] + A[i] ...

  2. 233 Matrix 矩阵快速幂

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

  3. 233 Matrix(矩阵快速幂+思维)

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

  4. HDU5015 233 Matrix —— 矩阵快速幂

    题目链接:https://vjudge.net/problem/HDU-5015 233 Matrix Time Limit: 10000/5000 MS (Java/Others)    Memor ...

  5. HDU.1575 Tr A ( 矩阵快速幂)

    HDU.1575 Tr A ( 矩阵快速幂) 点我挑战题目 题意分析 直接求矩阵A^K的结果,然后计算正对角线,即左上到右下对角线的和,结果模9973后输出即可. 由于此题矩阵直接给出的,题目比较裸. ...

  6. HDU5015 233 Matrix(矩阵高速幂)

    HDU5015 233 Matrix(矩阵高速幂) 题目链接 题目大意: 给出n∗m矩阵,给出第一行a01, a02, a03 ...a0m (各自是233, 2333, 23333...), 再给定 ...

  7. hdu 3117 Fibonacci Numbers 矩阵快速幂+公式

    斐波那契数列后四位可以用快速幂取模(模10000)算出.前四位要用公式推 HDU 3117 Fibonacci Numbers(矩阵快速幂+公式) f(n)=(((1+√5)/2)^n+((1-√5) ...

  8. HDU 5015 233 Matrix(网络赛1009) 矩阵快速幂

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

  9. HDU 2842 (递推+矩阵快速幂)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2842 题目大意:棒子上套环.第i个环能拿下的条件是:第i-1个环在棒子上,前i-2个环不在棒子上.每个 ...

随机推荐

  1. 跟我一起认识axure(二)

    创建企业网站页面步骤 第一步修改这里 变成 第一部分就完成了 第二部分部件窗口 在Axure中设计页面像小时候玩的拼图游戏,那么部件窗口就是专门用来存放拼图块的容器 使用部件窗口中常用的部件设计欢迎页 ...

  2. #define 和常量 const 的区别

    const 后的常量,程序对其中只能读不能修改. #include <iostream> using namespace std; int main() { const double pi ...

  3. chrome://inspect调试html页面空白,DOM无法加载的解决方案

    chrome://inspect调试html页面空白,DOM无法加载的解决方案 先描述一下问题 有一段时间没碰huilder hybird app 开发了,今天调试的时候 chrome://inspe ...

  4. SSH applicationContext.xml import异常

    近期在项目上,遇到了一个问题.在配置applicationContext.xml使用<import>标签引入其他的xml文件时,导致项目启动时过慢.有时还会引起启动异常.后来查到是xml文 ...

  5. KiCad EDA 过孔是否可以开窗?

    KiCad EDA 过孔是否可以开窗? 和传统的商业 EDA 不同,KiCad EDA 的过孔默认就是盖绿油. 在 KiCad 的过孔界面没有任何可以设置的地方,这也有一个好处,不过考虑过孔是否盖油. ...

  6. qt中绘制文字

    (1)颜色QPen (2) 字体QFont (3)位置与对齐 void CircleWidget::paintEvent(QPaintEvent *event) { QPainter painter( ...

  7. Python基础:13装饰器

    装饰器是一个很著名的设计模式,经常被用于有切面需求的场景,较为经典的应用有插入日志.性能测试.事务处理等.装饰器是解决这类问题的绝佳设计,有了装饰器,我们就可以抽离出大量函数中与函数功能本身无关的雷同 ...

  8. Part17—触摸屏显身手—Part17.1—原理简介

  9. HSV 和 HLS颜色空间

    颜色空间 颜色空间是特定的颜色组织:它提供了将颜色分类,并以数字图像表示的方法. RGB 是红绿蓝颜色空间.你可以将其视为 3D 空间,在这种情况下是立方体,其中任何颜色都可以用 R.G 和 B 值的 ...

  10. ras 加解密类,支持截取

    class RsaEncrypt{ private $_privateKey = false; private $_publicKey = false; /** * 私钥解密 * @param $da ...