#include <iostream> #include <vector> using namespace std; int n; int a[300003]; int T[300003]; int mod = 1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; } T[0] = 1 - (a[0] % 2); std::vector<int> sums; sums.push_back(a[0]); for (int i = 1; i < n; ++i) { sums.push_back(0); for (int j = i; j > 0; --j) { if (((a[i] + sums[j]) % mod) % 2 == 0) { T[i] = (T[i] + T[j - 1]) % mod; } sums[j] = (sums[j] + a[i]) % mod; } if (((a[i] + sums[0]) % mod) % 2 == 0) { T[i] = (T[i] + 1) % mod; } sums[0] = (sums[0] + a[i]) % mod; } cout << T[n - 1]; 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 | #include <iostream> #include <vector> using namespace std; int n; int a[300003]; int T[300003]; int mod = 1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; } T[0] = 1 - (a[0] % 2); std::vector<int> sums; sums.push_back(a[0]); for (int i = 1; i < n; ++i) { sums.push_back(0); for (int j = i; j > 0; --j) { if (((a[i] + sums[j]) % mod) % 2 == 0) { T[i] = (T[i] + T[j - 1]) % mod; } sums[j] = (sums[j] + a[i]) % mod; } if (((a[i] + sums[0]) % mod) % 2 == 0) { T[i] = (T[i] + 1) % mod; } sums[0] = (sums[0] + a[i]) % mod; } cout << T[n - 1]; return 0; } |