题干:

Bob's school has a big playground, boys and girls always play games here after school. 

To protect boys and girls from getting hurt when playing happily on the playground, rich boy Bob decided to cover the playground using his carpets. 

Meanwhile, Bob is a mean boy, so he acquired that his carpets can not overlap one cell twice or more. 

He has infinite carpets with sizes of 1×21×2 and 2×12×1, and the size of the playground is 4×n4×n. 

Can you tell Bob the total number of schemes where the carpets can cover the playground completely without overlapping? 

Input

There are no more than 5000 test cases. 

Each test case only contains one positive integer n in a line. 

1≤n≤10181≤n≤1018 

Output

For each test cases, output the answer mod 1000000007 in a line. 

Sample Input

1
2

Sample Output

1
5

题目大意:

给一个4*n的格子,你有两种方块(1*2),(2*1),放置的同时不能交叉重叠,询问放满的方案数。(n<=1e18)

解题报告:

考虑几种可行的状态:①0000,②1100,③0110,④0011,⑤1001,⑥1111。分别转移即可。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define F first
#define S second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const ll mod = 1e9 + 7;
const int MAX = 9;
struct Matrix {
	ll m[MAX][MAX];
} unix;
Matrix Mul(Matrix a,Matrix b) {
	Matrix c;
	memset(c.m,0,sizeof c.m);
	for(int i = 1; i<=6; i++) {
		for(int j = 1; j<=6; j++) {
			for(int k = 1; k<=6; k++) {
				c.m[i][j] = (c.m[i][j] + a.m[i][k] * b.m[k][j])%mod;
			}
		}
	}
	return c;
}
Matrix qpow(Matrix a,ll k) {
	Matrix res = unix;
	while(k) {
		if(k&1) res = Mul(res,a);
		a = Mul(a,a);
		k>>=1;
	}
	return res;
}
int main()
{	
	ll n;
	for(int i = 1; i<=6; i++) {
		unix.m[i][i] = 1;
	}
	Matrix trans;
	memset(trans.m,0,sizeof trans.m);
	trans.m[1][6]=trans.m[2][4]=trans.m[2][6]=trans.m[3][5]=trans.m[3][6]=trans.m[4][2]=trans.m[4][6]=trans.m[5][3]=1;
	trans.m[6][1]=trans.m[6][2]=trans.m[6][3]=trans.m[6][4]=trans.m[6][6]=1;
	while(~scanf("%lld",&n)) {
		Matrix ans = qpow(trans,n+1);
		printf("%lld\n",ans.m[1][6]);
		
	}
	return 0 ;
}

 

另一个题解:

https://blog.csdn.net/qq_32570675/article/details/77816353