1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long int lli;
lli MOD = 1000000007;

int main() {
    lli n;
    scanf("%lli", &n);
    vector<lli> nums(n);
    for (int i = 0; i < n; i++) {
        int num;
        scanf("%d", &num);
        nums[i] = num;
    }
    vector<lli> prefix(n+1);
    prefix[0] = 0;
    for (int i = 1; i <= n; i++) {
        prefix[i] = (prefix[i-1] + nums[i-1]) % MOD;
    }
    vector<vector<bool>> isValid(n, vector<bool>(n));
    lli sum = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i; j < n; j++) {
            isValid[i][j] = ((prefix[j+1] + MOD - prefix[i]) % MOD) % 2 == 0;
        }
    }
    vector<lli> cache(n+1);
    cache[n] = 1;

    for (int curr = n-1; curr >= 0; curr--) {
        lli sum = 0;
        for (int i = curr; i < n; i++) {
            if (isValid[curr][i]) {
                sum = (sum + cache[i + 1]) % MOD;
            }
        }
        cache[curr] = sum;
    }
    lli res = cache[0];
    cout << res << '\n';
    return 0;
}