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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include<bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    long long m = 1000000007;
    cin >> n;
    vector<long long> num(n+1);
    for(int i=1; i<=n; i++)
        cin >> num[i];
    long long sumofnums=0;
    for(int i=1; i<=n; i++)
        sumofnums+=num[i];
    if(sumofnums<1000000007)
    {
        for(int i=1; i<=n; i++)
            num[i]%=2;
        bool streak=false;
        int counter=0;
        for(int i=1; i<=n; i++)
        {
            if(num[i]==0 && streak)
                continue;
            if(num[i]==0 && !streak)
                ++counter;
            if(num[i]==1 && streak)
            {
                streak=false;
                ++counter;
                continue;
            }
            if(num[i]==1 && !streak)
                streak=true;
        }
        if(streak)
        {
            cout << 0 << "\n";
            return 0;
        }
        --counter;
        long long output=1;
        for(int i=0; i<counter; ++i)
        {
            output*=2;
            output%=m;
        }
        cout << output << "\n";
        return 0;
    }
    vector<vector<vector<long long>>> dp(n+1, vector<vector<long long>> (n+1, vector<long long> (2)));
    vector<long long> P(n+1);
    vector<long long> sum(n+1);
    for(int i=1; i<=n; i++)
    {
        sum[i]=(sum[i-1]+num[i]);
    }
    P[0]=1;
    for(int i=1; i<=n; i++)
    {
        if((num[i]%m)%2==1)
            dp[i][1][1]=P[i-1];
        else
            dp[i][1][0]=P[i-1];
        P[i]=dp[i][1][0];
        for(int j=2; j<=i; j++)
        {
            if((((sum[i]-sum[i-j])%m)%2)==1)
            {
                dp[i][j][1]=max(dp[i-1][j-1][0], dp[i-1][j-1][1]);
            }else{
                dp[i][j][0]=max(dp[i-1][j-1][0], dp[i-1][j-1][1]);
                P[i]+=dp[i][j][0];
                P[i]%=m;
            }
        }
    }
    cout << P[n] << "\n";
    return 0;
}