#include <bits/stdc++.h> using namespace std; #define ll long long const ll MAX = 3e5+10, MOD = 1e9+7; ll n, t[MAX], curr, wynik, dp[MAX]; int main() { ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n; for(int i = 1; i <= n; i++) cin >> t[i]; dp[n + 1] = 1; for(int i = n; i >= 1; i--) { ll suma = 0; /* if(t[i] % MOD % 2 == 0) dp[i] = 1; */ for(int j = i; j <= n; j++) { suma += t[j]; if((suma % MOD) % 2 == 0) dp[i] = (dp[i] + dp[j + 1]) % MOD; } } cout << dp[1] % MOD << "\n"; }
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 | #include <bits/stdc++.h> using namespace std; #define ll long long const ll MAX = 3e5+10, MOD = 1e9+7; ll n, t[MAX], curr, wynik, dp[MAX]; int main() { ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n; for(int i = 1; i <= n; i++) cin >> t[i]; dp[n + 1] = 1; for(int i = n; i >= 1; i--) { ll suma = 0; /* if(t[i] % MOD % 2 == 0) dp[i] = 1; */ for(int j = i; j <= n; j++) { suma += t[j]; if((suma % MOD) % 2 == 0) dp[i] = (dp[i] + dp[j + 1]) % MOD; } } cout << dp[1] % MOD << "\n"; } |