点击前往试题目录:https://blog.csdn.net/best335/article/details/99550556
#include
using namespace std;
const long long MOD = 1000000007;
int n;
long long dp[2][4][3]{{{0L,0L,0L},{0L,0L,0L},{1L,0L,0L},{0L,0L,0L}},{{0L,0L,0L},{0L,0L,0L},{1L,0L,0L},{0L,0L,0L}}};
//dp[循环索引][最后一位必须为此位][对应的状态]
int p[2]{1,0};//循环指针
int main(){
cin>>n;
for(int i=1;i
之前的题解:
#include
#include
using namespace std;
long long f[1000][4][3],N;
const long long& DP(const int& pos,const int& put_num,const int& status)
{
if (f[pos][put_num][status]!=-1L) return f[pos][put_num][status];
if (pos==0) if(put_num==2||put_num==0||status!=2) return f[pos][put_num][status]=0L; else return f[pos][put_num][status]=1L;
int xpos=pos-1,x1=(put_num==0||put_num==1)?2:0,x2=x1+1,x3=(put_num==0||put_num==2)?1:2;
return f[pos][put_num][status]=((put_num==2||put_num==0?DP(xpos,put_num==2?3:1,status):0L)+(status<2?DP(xpos,x1,x3):0L)+
(status==1?DP(xpos,x2,x3):0L)+(status==2?DP(xpos,x2,x3):0L)+DP(xpos,put_num,status))%1000000007L;
}
int main()
{
cin>>N;
memset(f,-1,sizeof(f));
cout<
之前等价的题解
#include
#include
using namespace std;
long long f[1000][4][3],N;
const long long& DP(const int& pos,const int& put_num,const int& status)
{
if (f[pos][put_num][status]!=-1L) return f[pos][put_num][status];
if (pos==0) if(put_num==2||put_num==0||status!=2) return f[pos][put_num][status]=0L; else return f[pos][put_num][status]=1L;
switch (put_num)
{
case 0:
switch(status)
{
case 0: return f[pos][put_num][status]=(DP(pos-1,2,1)+DP(pos-1,1,0)+DP(pos-1,0,0))%1000000007L;
case 1: return f[pos][put_num][status]=(DP(pos-1,2,1)+DP(pos-1,1,1)+DP(pos-1,3,1)+DP(pos-1,0,1))%1000000007L;
case 2: return f[pos][put_num][status]=(DP(pos-1,3,1)+DP(pos-1,1,2)+DP(pos-1,0,2))%1000000007L;
}
case 1:
switch(status)
{
case 0: return f[pos][put_num][status]=(DP(pos-1,2,2)+DP(pos-1,1,0))%1000000007L;
case 1: return f[pos][put_num][status]=(DP(pos-1,2,2)+DP(pos-1,3,2)+DP(pos-1,1,1))%1000000007L;
case 2: return f[pos][put_num][status]=(DP(pos-1,3,2)+DP(pos-1,1,2))%1000000007L;
}
case 2:
switch(status)
{
case 0: return f[pos][put_num][status]=(DP(pos-1,3,0)+DP(pos-1,0,1)+DP(pos-1,2,0))%1000000007L;
case 1: return f[pos][put_num][status]=(DP(pos-1,3,1)+DP(pos-1,0,1)+DP(pos-1,1,1)+DP(pos-1,2,1))%1000000007L;
case 2: return f[pos][put_num][status]=(DP(pos-1,3,2)+DP(pos-1,1,1)+DP(pos-1,2,2))%1000000007L;
}
case 3:
switch(status)
{
case 0: return f[pos][put_num][status]=(DP(pos-1,0,2)+DP(pos-1,3,0))%1000000007L;
case 1: return f[pos][put_num][status]=(DP(pos-1,0,2)+DP(pos-1,1,2)+DP(pos-1,3,1))%1000000007L;
case 2: return f[pos][put_num][status]=(DP(pos-1,1,2)+DP(pos-1,3,2))%1000000007L;
}
}
}
int main()
{
cin>>N;
memset(f,-1,sizeof(f));
cout<