题目描述:
代码如下:
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #define MOD 1000000007 5 6 long long a[1001] = {0}; 7 long long b[1001] = {0}; 8 9 int main(void) 10 { 11 int i,n; 12 long long sum; 13 long long a[1001] = {0,1,6,}; 14 long long b[1001] = {0,1,2,}; 15 scanf("%d",&n); 16 17 for (i=3 ; i<=n ; i++) 18 { 19 b[i] = (b[i-1]*2%MOD); //以固定方向行走的方案数 20 a[i] = (2*a[i-1]+b[i]+4*a[i-2])%MOD;//顶角的所有行走方案数 21 } 22 23 sum = 4*a[n]; //4个角可走的总方案数 24 for (i=2 ; i<n ; i++) 25 { 26 sum += ((8*b[n-i]*a[i-1])%MOD + (8*a[n-i]*b[i-1])%MOD)%MOD; 27 sum %= MOD; 28 } 29 30 if (n==1) 31 sum = 2; 32 33 printf("%ld",sum); 34 return 0; 35 }
代码参考:https://blog.csdn.net/cc_sonia/article/details/80375854
解题思路:
剩下的,就是走某一步(非顶角)的行走方案,具体参照上面博客提到的解法