AcWing 114514. 积木画
原题链接
简单
作者:
风轻云淡墨
,
2024-02-25 23:19:01
,
所有人可见
,
阅读 19
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
#define endl '\n'
const int N=1e7+10;
#define PLL pair<LL,LL>
#define f first
#define s second
const int mod=1e9+7;
priority_queue<PLL,vector<PLL>,greater<PLL>>q;
int f[2][4];
int g[4][4]=
{
{1,1,1,1}, //第一二排都没遮挡00 每一行的意义 里边的1代表可以转化 00 01 10 11
{0,0,1,1}, //第二排遮挡01
{0,1,0,1}, //第一排遮挡10
{1,0,0,0}
};
int main()
{
ios::sync_with_stdio(0);cin.tie(0);
LL n;cin>>n;
f[1][0]=1;
for(int i=1;i<=n;i++)
{
memset(f[(i+1)&1],0,sizeof f[0]);//清空一下
for(int j=0;j<4;j++)
for(int k=0;k<4;k++)
{
if(g[j][k])
f[i+1&1][k]=(f[i+1&1][k]+f[i&1][j])%mod;//滚动数组
}
}
cout<<f[n+1&1][0]<<endl;
}