http://acm.hdu.edu.cn/showproblem.php?pid=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 a0,1 = 233,a0,2 = 2333,a0,3 = 23333…) Besides, in 233 matrix, we got ai,j = ai-1,j +ai,j-1( i,j ≠ 0). Now you have known a1,0,a2,0,…,an,0, could you tell me an,m in the 233 matrix?
There are multiple test cases. Please process till EOF.
For each case, the first line contains two postive integers n,m(n ≤ 10,m ≤ 109). The second line contains n integers, a1,0,a2,0,…,an,0(0 ≤ ai,0 < 231).
For each case, output an,m mod 10000007.
1 1
1
2 2
0 0
3 7
23 47 16
234
2799
72937
有一个矩阵横排第一行初始是0 233 2333 23333...
,然后给出计算公式a[i][j] = a[i - 1][j] + a[i][j - 1]
,然后给出了n m
和第一列的各值要求计算a[n][m]
的值。
第一列元素为:
0
a1
a2
a3
a4
转化为:
23
a1
a2
a3
a4
3
则第二列为:
23*10+3 = 233
23*10+3+a1 = 233 + a1
23*10+3+a1+a2 = 233 + a1 + a2
23*10+3+a1+a2+a3 = 233 + a1 + a2 + a3
23*10+3+a1+a2+a3+a4 = 233 + a1 + a2 + a3 +a4
3 = 3
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define il inline
#define ll long long
#define ull unsigned long long
using namespace std;
#define maxn 107
long long n, m, a[maxn], result[maxn], mod = 10000007;
struct mat {
long long m[maxn][maxn];
mat(long long i=0) {
memset(m,0,sizeof m);
if(i == 1)
for(long long i=0 ; i1;
}
mat operator * (const mat tmp) const {
mat ret;
for(long long i=0,x ; ifor(long long j=0 ; x=0,jfor(long long k=0 ; kreturn ret;
}
mat qpow(long long n) {
mat ret = 1, tmp = *this;
while(n!=0) {
if(bool(n&1)) ret = ret * tmp;
tmp = tmp * tmp;
n >>= 1;
}
return ret;
}
void show() {
mat tmp = *this;
for(long long i=0 ; ifor(long long j=0 ; j1 ; j++) {
cout << tmp.m[i][j] << ' ';
}
cout << tmp.m[i][n-1] << '\n';
}
cout << '\n';
}
};
mat calc(const mat &a, const mat &b, long long h, long long l, long long s) {
mat ret;
for(long long i=0, x ; ifor(long long j=0 ; x=0, jfor(long long k=0 ; kreturn ret;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(false);cin.tie(0);
while(cin >> n >> m) {
mat base = 1, tmp, ans = 0;
ans.m[0][0] = 23;
for(long long i=1 ; i<=n ; i++) cin >> ans.m[i][0];
n++; base.m[n][n] = 1, ans.m[n][0] = 3;
for(long long i=0 ; i1, base.m[i][0] = 10;
for(long long i=0 ; ifor(long long j=1 ; j<=i; j++) base.m[i][j] = 1;
n++;
tmp = base.qpow(m);
ans = calc(tmp,ans,n,1,n);
cout << ans.m[n-2][0] << '\n';
}
return 0;
}