hdu 5015 233 Matrix(矩阵快速幂)

233 Matrix

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 884    Accepted Submission(s): 531


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 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
 


把第一行的233数列全部左移一位就可以推出一个递推矩阵来

比如输入的是

n m

a1 a2 a3 a4 、... 、an


可以构造成

B[0][0]=3

B[1][0]=233

B[2][0]=a1

B[3][0]=a2

B[4][0]=a3

...

B[n+1][0]=an


递推矩阵A:

1 0 0 0 0 ... 0 0

1 10 0 0 0 ... 0 0

0 1 1 0 0 ... 0 0

0 1 1 1 0 ... 0 0

0 1 1 1 1 ... 0 0

...

0 1 1 1 1 ... 1 0

0 1 1 1 1 ... 1 1


然后就是矩阵(A^m)*B第n项就是答案


#include 
#include 
#include 
#include 
#define LL long long
using namespace std;
const LL mod = 10000007;
const int maxn=15;
struct node
{
    LL mat[maxn][maxn];
    int r,c;
}A,B,C,D;
int n,m,a[15];

void initial()
{
     A.c=A.r=D.r=D.c=n+2;
     B.r=n+2,B.c=1;
     for(int i=0;i>= 1;
    }
    return ret;
}

int main()
{
     while(scanf("%d %d",&n,&m)!=EOF)
     {
         for(int i=1;i<=n;i++)  scanf("%d",&a[i]);
         initial();
         C=pow_mod(A,m);
         node ans=mul(C,B);
         printf("%I64d\n",ans.mat[n+1][0]);
     }
     return 0;
}



你可能感兴趣的:(数论)