HDU 5015 233 Matrix --矩阵快速幂
程序员文章站
2022-07-03 18:25:28
...
题意:
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<bits/stdc++.h>
#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<n;i++)
scanf("%lld",&(b.a[0][2+i]));
while(m)
{
if(m&1) b=cheng(b,a,true);
m>>=1;
a=cheng(a,a,false);
}
printf("%lld\n",(b.a[0][n+1]%N+N)%N);
}
return 0;
}
上一篇: HDU 5015 233 Matrix(矩阵快速幂)
下一篇: 百度Apollo学习笔记(更新中)
推荐阅读
-
HDU 2256Problem of Precision(矩阵快速幂)
-
POJ3233Matrix Power Series(矩阵快速幂)
-
Recursive sequence(HDU5950 矩阵快速幂)
-
hdu4990——多解矩阵快速幂
-
hdu4990矩阵快速幂
-
HDU4990 Reading comprehension【矩阵快速幂】
-
HDU4990 Reading comprehension【矩阵快速幂】
-
HDU 2256Problem of Precision(矩阵快速幂)
-
hdu 5015 矩阵快速幂
-
矩阵快速幂专题 HDU1757 HDU1575 HDU2604 HDU2256 CF185A HDU2276 HDU2842