一列一列地推就可以了
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
int n, m;
const int mod=10000007;
struct Matrix{
int num[15][15];
Matrix operator*(const Matrix &x)const{
Matrix re;
for(int i=0; i<=n+1; i++)
for(int j=0; j<=n+1; j++){
re.num[i][j] = 0;
for(int k=0; k<=n+1; k++)
re.num[i][j] = (re.num[i][j] + (ll)num[i][k]*x.num[k][j]) % mod;
}
return re;
}
}dan, zhu, yua;
Matrix ksm(int b){
Matrix re=dan;
while(b){
if(b&1) re = re * zhu;
zhu = zhu * zhu;
b >>= 1;
}
return re;
}
int main(){
for(int i=0; i<=11; i++)
dan.num[i][i] = 1;
while(scanf("%d %d", &n, &m)!=EOF){
yua.num[0][0] = 23;
for(int i=1; i<=n; i++)
scanf("%d", &yua.num[0][i]);
yua.num[0][n+1] = 1;
for(int i=0; i<=n+1; i++)
for(int j=0; j<=n+1; j++){
if(j==n+1){
if(i==n+1) zhu.num[i][j] = 1;
else zhu.num[i][j] = 0;
}
else if(i==0) zhu.num[i][j] = 10;
else if(i==n+1) zhu.num[i][j] = 3;
else if(i<=j) zhu.num[i][j] = 1;
else zhu.num[i][j] = 0;
}
cout<<(yua*ksm(m)).num[0][n]<<endl;
}
return 0;
}