题意:
ai,j = a i-1,j +a i,j-1( i,j > 0) , a0,i=23333...., i+1个3,ai,0为输入的数值
给出n,m,给出(a0,1 ), ( a0,n)
求an,m
思路:
我们知道这是NXM的矩阵
试着画出该矩阵,想推出ai,j发现推不出来,但是可以推出下一列
应该一目了然了吧
#include
#define N 10000007
using namespace std;
struct node
{
long long a[12][12];
};
const node A={
{
{1,1 ,0,0,0,0,0,0,0,0,0,0},
{0,10,1,1,1,1,1,1,1,1,1,1},
{0,0 ,1,1,1,1,1,1,1,1,1,1},
{0,0 ,0,1,1,1,1,1,1,1,1,1},
{0,0 ,0,0,1,1,1,1,1,1,1,1},
{0,0 ,0,0,0,1,1,1,1,1,1,1},
{0,0 ,0,0,0,0,1,1,1,1,1,1},
{0,0 ,0,0,0,0,0,1,1,1,1,1},
{0,0 ,0,0,0,0,0,0,1,1,1,1},
{0,0 ,0,0,0,0,0,0,0,1,1,1},
{0,0 ,0,0,0,0,0,0,0,0,1,1},
{0,0 ,0,0,0,0,0,0,0,0,0,1}
}
};
const node B={
{
{3,233,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0}
}
};
node cheng(node a,node b,bool f)
{
node c;
memset(c.a,0,sizeof(c.a));
for(int i=0;i<12;i++){
if(f&&i==1) break;
for(int j=0;j<12;j++)
for(int k=0;k<12;k++)
c.a[i][j]=(c.a[i][j]+(a.a[i][k]*b.a[k][j])%N)%N;
}
return c;
}
int main()
{
int t,n,m,sum;
node a,b;
while(~scanf("%d%d",&n,&m))
{
if(n==m&&n==0)
{
printf("0\n");
continue;
}
a=A;
b=B;
for(int i=0;i>=1;
a=cheng(a,a,false);
}
printf("%lld\n",(b.a[0][n+1]%N+N)%N);
}
return 0;
}