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
using namespace std;
typedef long long LL;
#define rep(i,a,b) for(int i=a;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>=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;
}