#include <vector> #include <cstdio> const unsigned pvalue = 1e9 + 7; inline bool is_mopadulo(unsigned long long v) { return (v % pvalue) % 2 == 0; } int main() { int n; scanf("%d", &n); std::vector<int> tab(n, 0); for (int i = 0; i < n; ++i) scanf("%d", &tab[i]); std::vector<unsigned> mem(n+1, 0); unsigned long long sum = 0; for (size_t i = 0; i < n; ++i) { unsigned long long v = 0; sum += tab[i]; if (is_mopadulo(sum)) v = 1; unsigned long long sumt = sum; for (size_t j = 0; j < i; ++j) { sumt -= tab[j]; if (is_mopadulo(sumt)) { v += mem[j]; v %= pvalue; } } mem[i] = v; } printf("%u\n", mem[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 38 39 40 41 42 43 44 45 | #include <vector> #include <cstdio> const unsigned pvalue = 1e9 + 7; inline bool is_mopadulo(unsigned long long v) { return (v % pvalue) % 2 == 0; } int main() { int n; scanf("%d", &n); std::vector<int> tab(n, 0); for (int i = 0; i < n; ++i) scanf("%d", &tab[i]); std::vector<unsigned> mem(n+1, 0); unsigned long long sum = 0; for (size_t i = 0; i < n; ++i) { unsigned long long v = 0; sum += tab[i]; if (is_mopadulo(sum)) v = 1; unsigned long long sumt = sum; for (size_t j = 0; j < i; ++j) { sumt -= tab[j]; if (is_mopadulo(sumt)) { v += mem[j]; v %= pvalue; } } mem[i] = v; } printf("%u\n", mem[n-1]); return 0; } |