枚举第一个格子有无雷,O(n)检验
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <stack>
#include <deque>
#include <queue>
#include <map>
#include <vector>
#include <set>
typedef long long LL;
typedef double DB;
typedef unsigned US;
#define For(i, s, t) for(int i = (s); i <= (t); i++)
#define Ford(i, s, t) for(int i = (s); i >= (t); i--)
#define Rep(i, n) for(int i = 0; i < (n); i++)
#define Repn(i, n) for(int i = ((n) - 1); i >= 0; i--)
#define rep(i, s, t) for(int i = (s); i < (t); i++)
#define repn(i, s, t) for(int i = ((s) - 1); i >= (t); i--)
#define FU(t, c) for(__typeof((c).begin()) t = (c).begin(); t != (c).end(); t++)
#define FD(t, c) for(__typeof((c).rbegin()) t = (c).rbegin(); t != (c).rend(); t--)
#define pi (3.1415926535)
#define mk make_pair
#define sqr(x) ((x) * (x))
#define ft first
#define sd second
#define abs(x) ((x) > 0 ? (x) : (-(x)))
#define max(x, y) ((x) > (y) ? (x) : (y))
#define min(x, y) ((x) < (y) ? (x) : (y))
#define clr(c, t) (memset((c), (t), sizeof((c))))
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define Sma_let(x) (((x) >= 'a') && ((x) <= 'z'))
#define Big_let(x) (((x) >= 'A') && ((x) <= 'Z'))
#define letter(x) ((Sma_let((x))) || (Big_let((x))))
#define MIT 2147483647
#define INF 1000000000
#define MLL 1000000000000000000LL
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
using namespace std; // yzx'Rp ++
inline void SETIO(string name) {
string IN = name + ".in", OUT = name + ".out";
freopen(IN.c_str(), "r", stdin), freopen(OUT.c_str(), "w", stdout);
}
const int maxn=10000+10;
int S[maxn],F[maxn]={},n,Ans=0;
inline void Input() {
scanf("%d", &n);
For(i, 1, n) scanf("%d", &S[i]);
}
inline bool Check(int p) { return F[p - 1] + F[p] + F[p + 1] == S[p]; }
inline void Dfs(int p) {
if(p == n+1) {
if(Check(p - 1)) Ans++;
return;
}
F[p] = 0;
if(p == 1 || Check(p - 1)) Dfs(p + 1);
F[p] = 1;
if(p == 1 || Check(p - 1)) Dfs(p + 1);
}
inline void Solve() {
Dfs(1);
printf("%d\n", Ans);
}
int main() {
#ifndef ONLINE_JUDGE
SETIO("1088");
#endif
Input();
Solve();
return 0;
}