Problem Description
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 are the question:suppose we have a matrix called 233 matrix. In the first line, it would is 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 there are known a1,0,a2,0,..., an,0, could you tell me an,m in the 233 matrix?
Input
There is multiple test cases. Please process till EOF.
For each case, the first line contains the postive integers n,m (n≤10,m≤109). The second line contains n integers, a1,0,a2,0,..., an,0 (0≤ai,0 < 231).
Output
For each case, output an,m mod 10000007.
Sample Input
1 1
1
2 2
0 0
3 7
23 47 16
Sample Output
234
2799
72937
http://blog.csdn.net/u011721440/article/details/39401515
Ideas:
The first column elements are:
0
A1
A2
A3
A4
Translate to:
23
A1
A2
A3
A4
3
The second column is:
23*10+3
23*10+3+a1
23*10+3+a1+a2
23*10+3+a1+a2+a3
23*10+3+a1+a2+a3+a4
3
Based on the recursive relationship between the front and back columns, the elements of matrix A can be found with the equation:
Just follow the diagram to construct the matrix, and I can't believe this is going to find a recursive type.
#include <iostream> #include <cstring> #include <string> #include <vector> #include <queue > #include <cstdio> #include <set> #include <math.h> #include <algorithm> #include <queue&
Gt
#include <iomanip> #define INF 0x3f3f3f3f #define MAXN 10000005 #define MOD 10000007 using namespace std;
const int N = 13;
Long Long m,n;
struct Matrix {long long mat[n][n];};
Matrix Mul (Matrix A,matrix b) {matrix res;
for (int i=0, i<=n+1; ++i) for (int j=0; j<=n+1; ++j) {res.mat[i][j]=0;
for (int k=0; k<=n+1; ++k) {res.mat[i][j]+=a.mat[i][k]*b.mat[k][j];
Res.mat[i][j]%=mod;
}} return res;
} Matrix Pow_matrix (Matrix A,long long k) {matrix res;
memset (res.mat,0,sizeof (Res.mat));
for (int i=0;i<=n+1;++i) res.mat[i][i]=1;
while (k!=0) {if (k%2) Res=mul (res,a); A=mul (A,a);
k>>=1;
} return res;
} int main () {Matrix Tmp,arr;
while (~SCANF ("%i64d%i64d", &n,&m)) {memset (arr.mat,0,sizeof (Arr.mat));
memset (tmp.mat,0,sizeof (Tmp.mat));
arr.mat[0][0]=23;
for (int i=1;i<=n;++i) scanf ("%i64d", &arr.mat[i][0]);
arr.mat[n+1][0]=3;
for (int i=0;i<=n;++i) {tmp.mat[i][0]=10;
Tmp.mat[i][n+1]=1;
} tmp.mat[n+1][n+1]=1;
for (int i=1;i<=n;++i) for (int j=1;j<=i;++j) tmp.mat[i][j]=1;
Matrix P=pow_matrix (tmp,m);
P=mul (P,arr);
Long Long ans=p.mat[n][0]%mod;
printf ("%i64d\n", ans);
} return 0;
}