Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define FOR(i, a, b) for(int i = a; i < b; ++i)
- #define REP(i, n) FOR(i, 0, n)
- #define _ << " " <<
- #define sz(x) ((int) x.size())
- #define pb(x) push_back(x)
- #define TRACE(x) cerr << #x << " = " << x << endl
- typedef long long ll;
- typedef pair<int, int> point;
- const int mod = 1e9 + 7;
- int add(int x, int y) {x += y; if(x >= mod) return x - mod; return x;}
- int sub(int x, int y) {x -= y; if(x < 0) return x + mod; return x;}
- int mul(int x, int y) {return (ll) x * y % mod;}
- const int MAXN = 505;
- int n, a[MAXN], dp[MAXN][MAXN];
- int main(){
- ios_base::sync_with_stdio(false); cin.tie(0);
- cin >> n;
- REP(i, n)
- cin >> a[i];
- if(a[0] != 0){
- cout << 0;
- return 0;
- }
- dp[0][0] = 1;
- FOR(i, 1, n){
- int mx = min(i, n - 1 - i);
- FOR(j, 0, n){
- if(j > mx) continue;
- if(a[i] != -1 && j != a[i]) continue;
- if(j > 0)
- dp[i][j] = add(dp[i][j], dp[i - 1][j - 1]);
- dp[i][j] = add(dp[i][j], dp[i - 1][j]);
- dp[i][j] = add(dp[i][j], dp[i - 1][j + 1]);
- }
- }
- cout << dp[n - 1][0];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement