#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; long long wynik; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n; cin >> n; long long a[n+1]; a[0] = 0; for(int i = 1; i <= n; i++){ cin >> a[i]; } long long px[n+1]; px[0] = 0; for(int i = 1; i <= n; i++){ px[i] = px[i-1] + a[i]; } long long dp[n+1]; dp[0] = 0; for(long long i = 1; i <= n; i++){ if((px[i]%MOD)&1) dp[i] = 0; else dp[i] = 1; for(long long j = i; j > 0; j--){ if(((px[i] - px[j-1])%MOD)%2 == 0) dp[i] = (dp[j-1]+dp[i])%MOD; } } cout << dp[n]%MOD; return 0; }
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 | #include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; long long wynik; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n; cin >> n; long long a[n+1]; a[0] = 0; for(int i = 1; i <= n; i++){ cin >> a[i]; } long long px[n+1]; px[0] = 0; for(int i = 1; i <= n; i++){ px[i] = px[i-1] + a[i]; } long long dp[n+1]; dp[0] = 0; for(long long i = 1; i <= n; i++){ if((px[i]%MOD)&1) dp[i] = 0; else dp[i] = 1; for(long long j = i; j > 0; j--){ if(((px[i] - px[j-1])%MOD)%2 == 0) dp[i] = (dp[j-1]+dp[i])%MOD; } } cout << dp[n]%MOD; return 0; } |