233 Matrix HDU - 5015

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 a i,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?

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 ≤ 10 9). The second line contains n integers, a 1,0,a 2,0,...,a n,0(0 ≤ a i,0 < 2 31).

Output

For each case, output a n,m mod 10000007.

Sample Input

1 1
1
2 2
0 0
3 7
23 47 16

Sample Output

234
2799
72937


      

Hint

 

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define per(i,a,b) for(int i=b-1;i>=a;--i)

const int mod=10000007;


/*
当时总是想暑假集训的那道题,只不过那个是有更新的,这道题没有更新
总想着组合数,但是求答案的时候遇到一个巨坑的点,这个数不是质数,所以后面
没有逆元,导致复杂度特别高

还是菜啊,没有想到用 快速幂 来加速
其实他每一行的递推关系是固定的,我们应该想一下递推

*/

/*
!!!一定要标清 矩阵的 长和宽
*/
struct Mar{
    int n,m;
    LL mar[20][20];
    Mar(int _n=0,int _m=0){
        n=_n,m=_m;
        memset(mar,0,sizeof(mar));
    }
    Mar operator*(Mar b){
        Mar ans(n,b.m);
        for(int i=0;i<n;i++){
            for(int j=0;j<b.m;j++){
                ans.mar[i][j]=0;
                for(int k=0;k<m;k++){
                    ans.mar[i][j]=(ans.mar[i][j]+mar[i][k]*b.mar[k][j]%mod)%mod;
                }
            }
        }
        return ans;
    }
    void show(){
        printf("******\n");
        rep(i,0,n){
            rep(j,0,m){
                printf("%6lld ",mar[i][j]);
            }
            printf("\n");
        }
    }
}E;


LL val[20][5];

Mar pow_mod_mar(Mar base,int n,int mod){
    Mar ans=E;
    while(n){
        if(n&1)ans=ans*base;
        base=base*base;
        n>>=1;
    }
    return ans;
}

int main(){

    int n,m;
    while(scanf("%d %d",&n,&m)==2){

        E.n=n+2,E.m=n+2;
        rep(i,0,n+2)E.mar[i][i]=1;

        rep(i,1,n+1)scanf("%lld",&val[i][0]);

        Mar ST(n+2,1);
        ST.mar[0][0]=233;
        rep(i,1,n+1)ST.mar[i][0]=(ST.mar[i-1][0]+val[i][0])%mod;
        ST.mar[n+1][0]=3;

        Mar mid(n+2,n+2);
        rep(i,0,n+1) mid.mar[i][0]=10,mid.mar[i][n+1]=1;
        rep(i,0,n+1) rep(j,1,i+1) mid.mar[i][j]=1;
        mid.mar[n+1][n+1]=1;
    
        mid=pow_mod_mar(mid,m-1,mod);
        ST=mid*ST;
        printf("%lld\n",ST.mar[n][0]);
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值