POJ - 3233 Matrix Power Series

传送门

 

Solution:

1.矩阵分块 题解在这里

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<algorithm>
 5 #include<cstring>
 6 #define R register
 7 #define go(i,a,b) for(R int i=a;i<=b;i++)
 8 #define yes(i,a,b) for(R int i=a;i>=b;i--)
 9 #define ll long long
10 #define db double
11 using namespace std;
12 ll n,m;int mod;
13 struct node{ll mt[3][3];};
14 node calc(node x,node y,int a,int b,int c)
15 {
16     node z;memset(z.mt,0,sizeof(z.mt));
17     go(i,1,a)
18         go(j,1,b)
19         go(k,1,c)
20         z.mt[i][j]=(z.mt[i][j]+x.mt[i][k]*y.mt[k][j])%mod;
21     return z;
22 }
23 node a,b,c;
24 void sol()
25 {
26     while(m)
27     {
28         if(m&1) b=calc(b,a,2,2,2);
29         m>>=1;a=calc(a,a,2,2,2);
30     }
31 }
32 int main()
33 {
34     scanf("%lld",&n);m=n-2;mod=1000000007;
35     if(n<=2){printf("1");return 0;}
36     a.mt[1][1]=1,a.mt[1][2]=1,a.mt[2][1]=1,a.mt[2][2]=0;
37     b.mt[1][1]=1,b.mt[1][2]=0,b.mt[2][1]=0,b.mt[2][2]=1;
38     c.mt[1][1]=1;c.mt[2][1]=1;
39     sol();
40     c=calc(b,c,2,1,2);
41     printf("%lld",c.mt[1][1]);
42     return 0;
43 }
View Code

但是这个代码有点问题 就是k=1和k=2的时候会错,是因为递推式子的原因,详见题解

但还是AC了 因为没有k=1,2这么水的数据 这里说一下我就不改了

2.分治 题解

 

没啦qwq

 

posted @ 2019-02-16 08:00  DTTTTTTT  阅读(187)  评论(0编辑  收藏  举报