题意:
矩阵的第一行是
23 233 2333 23333…..
给出n*m矩阵的第一列,其他都满足F[i,j]=F[i-1,j]+F[i,j-1]
求F[n,m]
思路:
我们对于每行进行推导,发现一些规律
F[0]=F[0]*10+3
F[1]=F[1]+F[0]*10+3
F[2]=F[2]+F[1]+F[0]*10+3
….
这样,我们就能搞出来一个n+2*n+2的矩阵,比如n==3的时候
10 10 10 10 0
0 1 1 1 0
0 0 1 1 0
0 0 0 1 0
1 1 1 1 1
原矩阵就是
A[0] A[1] A[2] A[3] 3
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
另外…这道题能用数学方法过…0ms(ORZ
给出链接
http://blog.csdn.net/acvcla/article/details/39274391utm_source=tuicool&utm_medium=referral
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define lowbit(x) (x&(-x))
typedef long long LL;
const int maxn = 100005;
const int inf=(1<<28)-1;
#define Matrix_Size 12
const LL MOD = 1e7+7;
int Size;
struct Matrix
{
LL mat[Matrix_Size][Matrix_Size];
void clear()
{
memset(mat,0,sizeof(mat));
}
void output()
{
for(int i = 0;i < Size;i++)
{
for(int j = 0;j < Size;j++)
printf("%d ",mat[i][j]);
printf("\n");
}
}
Matrix operator *(const Matrix &b)const
{
Matrix ret;
for(int i = 0;i < Size;i++)
for(int j = 0;j < Size;j++)
{
ret.mat[i][j] = 0;
for(int k = 0;k < Size;k++)
{
long long tmp = (long long)mat[i][k]*b.mat[k][j]%MOD;
ret.mat[i][j] = (ret.mat[i][j]+tmp);
if(ret.mat[i][j]>=MOD)
ret.mat[i][j] -= MOD;
if(ret.mat[i][j]<0)//注意是否需要MOD
ret.mat[i][j] += MOD;
}
}
return ret;
}
};
Matrix pow_M(Matrix a,long long n)
{
Matrix ret;
ret.clear();
for(int i = 0;i < Size;i++)
ret.mat[i][i] = 1;
Matrix tmp = a;
while(n)
{
if(n&1)ret = ret*tmp;
tmp = tmp*tmp;
n>>=1;
}
return ret;
}
int main()
{
LL n,m;
while(~scanf("%lld%lld",&n,&m))
{
Size=n+2;
Matrix A,B;
A.clear();B.clear();
A.mat[0][0]=23;
for(int i=1;i<=n;++i)
scanf("%lld",&A.mat[0][i]);
A.mat[0][n+1]=3;
for(int i=0;i<=n;++i)
{
B.mat[0][i]=10;
for(int j=1;j<=i;++j)
B.mat[j][i]=1;
B.mat[n+1][i]=1;
}
B.mat[n+1][n+1]=1;
//B.output();
if(m==0)
{
printf("%lld\n",A.mat[0][n]);
continue;
}
B=pow_M(B,m);
A=A*B;
printf("%d\n",A.mat[0][n]);
}
return 0;
}