据说可以从头两格确定状态,但是我没有多想,直接就上了dfs
/*
1.在一头一尾加入空格?不行,还是要特判,或者加0或1?
2.据说确定前两格检验就行了,不过我还是深搜?
3.默认不需要取模吗?废话深搜(暴力)假如要取模早就T了,先试一下暴力深搜对不对
4.用x1、x2、x3表示格子附近的第二行的状态
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int N;
int s[10005];
int ans;
void dfs(int id,int pl,int x1,int x2,int x3){
if(id==1){
if(pl==0){
//第一个不放
dfs(id+1,0,x2,x3,s[id+2]);
dfs(id+1,1,x2,x3,s[id+2]);
}
else{
//第一个放
x2--;
x3--;
if(x2<0||x3<0)
return;
dfs(id+1,0,x2,x3,s[id+2]);
dfs(id+1,1,x2,x3,s[id+2]);
}
}
else if(id==N){
if(pl==0){
//最后一个不放
if(x1==0&&x2==0){//x3不存在
ans++;
return;
}
else
return;
}
else{
//最后一个放
x1--;
x2--;
if(x1==0&&x2==0){
ans++;
return;
}
else{
return;
}
}
}
else{
if(pl==0){
//中间不放
if(x1!=0)//有个格子没放完就被舍弃了
return;
else{
dfs(id+1,0,x2,x3,s[id+2]);
dfs(id+1,1,x2,x3,s[id+2]);
}
}
else{
//中间放
x1--;
x2--;
x3--;
if(x1!=0)//有个格子没放完就被舍弃了
return;
else{
dfs(id+1,0,x2,x3,s[id+2]);
dfs(id+1,1,x2,x3,s[id+2]);
}
}
}
}
int main(){
while(~scanf("%d",&N)){
for(int i=1;i<=N;i++){
scanf("%d",&s[i]);
}
ans=0;
dfs(1,0,-1,s[1],s[2]);
dfs(1,1,-1,s[1],s[2]);
printf("%d\n",ans);
}
}
2.