#include <bits/stdc++.h> #define st first #define nd second #define pb push_back #define BOOST ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); #define PI 3.14159265359 using namespace std; typedef long long ll; constexpr ll MOD = 1000000007, sup = 29; constexpr ll MOD_1 = 1234567891, sup_1 = 1009; constexpr ll MOD_2 = 1000000009, sup_2 = 107; constexpr int MXN = 300000+10, CZAPA = (1<<19)/*, INF = 1000000000*/; constexpr ll INF = 1000000000000000000; ll tab[MXN], dp[MXN], pref[MXN]; int main(){ BOOST; int n; cin>> n; for(int i=1; i<=n; i++){ cin>> tab[i]; pref[i] = (pref[i-1] + tab[i])%MOD; } dp[0] = 1; for(int i=1; i<=n; i++){ for(int j=0; j<i; j++){ if(((pref[i]-pref[j]+MOD)%MOD)%2 == 0){ dp[i] += dp[j]; dp[i] %= MOD; } } } cout<< dp[n]%MOD << '\n'; 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 35 36 37 38 39 40 41 42 43 44 | #include <bits/stdc++.h> #define st first #define nd second #define pb push_back #define BOOST ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); #define PI 3.14159265359 using namespace std; typedef long long ll; constexpr ll MOD = 1000000007, sup = 29; constexpr ll MOD_1 = 1234567891, sup_1 = 1009; constexpr ll MOD_2 = 1000000009, sup_2 = 107; constexpr int MXN = 300000+10, CZAPA = (1<<19)/*, INF = 1000000000*/; constexpr ll INF = 1000000000000000000; ll tab[MXN], dp[MXN], pref[MXN]; int main(){ BOOST; int n; cin>> n; for(int i=1; i<=n; i++){ cin>> tab[i]; pref[i] = (pref[i-1] + tab[i])%MOD; } dp[0] = 1; for(int i=1; i<=n; i++){ for(int j=0; j<i; j++){ if(((pref[i]-pref[j]+MOD)%MOD)%2 == 0){ dp[i] += dp[j]; dp[i] %= MOD; } } } cout<< dp[n]%MOD << '\n'; return 0; } |