f[n][m]=f[n-1][m]+f[n][m-1]的形式,可以通过下三角矩阵的线性组合体现出来
//#include<bits/stdc++.h> //#pragma comment(linker, "/STACK:1024000000,1024000000") #include<stdio.h> #include<algorithm> #include<queue> #include<string.h> #include<iostream> #include<math.h> #include<set> #include<map> #include<vector> #include<iomanip> using namespace std; const double pi=acos(-1.0); #define ll long long #define pb push_back #define sqr(a) ((a)*(a)) #define dis(a,b) sqrt(sqr(a.x-b.x)+sqr(a.y-b.y)) const double eps=1e-10; const int maxn=5e4+56; const int inf=0x3f3f3f3f; const ll mod=1e7+7; ll arr[maxn]; struct mat{ ll a[15][15]; ll n,m; mat(){memset(a,0,sizeof a);n=0;m=0;} mat(ll x,ll y){memset(a,0,sizeof a);n=x;m=y;} mat operator* (const mat &rhs)const{ mat ans; ans.n=n;ans.m=rhs.m; for(int i=1;i<=n;i++){ for(int j=1;j<=rhs.m;j++){ for(int k=1;k<=m;k++){ ans.a[i][j]=(ans.a[i][j]+a[i][k]*rhs.a[k][j]+mod)%mod; } } } return ans; } mat operator^ (ll rhs)const{ mat ans(n,n),b=*this; for(int i=1;i<=n;i++)ans.a[i][i]=1; for(;rhs;rhs>>=1,b=b*b) if(rhs&1)ans=ans*b; return ans; } }; int main(){ ll n,m; while(~scanf("%lld%lld",&n,&m)){ for(int i=2;i<=n+1;i++){scanf("%lld",&arr[i]);} arr[1]=1ll*23;arr[n+2]=1ll*3; mat mult(n+2,n+2); mult.a[n+2][n+2]=1; for(int i=1;i<=n+1;i++)for(int j=1;j<=n+2;j++){ if(j==1){mult.a[i][j]=10;} else if(i>=j){mult.a[i][j]=1;} else if(j==n+2){mult.a[i][j]=1;} } mat fin=mult^(m); ll ans=0; for(int j=1;j<=n+2;j++){ ans=(ans+fin.a[n+1][j]*arr[j]%mod)%mod; } printf("%lld ",ans); } }