#include <cstdio> #include <algorithm> #include <vector> using namespace std; #define UL unsigned long #define MOD(x) ((x) % 1000000007) int main() { int n; vector<UL> tab; UL agg[300002]; scanf("%d", &n); for (int i = 0; i < n; ++i) { int x; scanf("%d", &x); tab.push_back(x); } agg[0] = 1; for (int i = 0; i < n; ++i) { if (agg[i] == 0) { continue; } UL suma = 0; for (int j = i; j < n; ++j) { suma = MOD(suma + tab[j]); if (suma % 2 == 0) { agg[j+1] = MOD(agg[j+1] + agg[i]); } } } printf("%d\n", agg[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 28 29 30 31 32 33 34 35 36 | #include <cstdio> #include <algorithm> #include <vector> using namespace std; #define UL unsigned long #define MOD(x) ((x) % 1000000007) int main() { int n; vector<UL> tab; UL agg[300002]; scanf("%d", &n); for (int i = 0; i < n; ++i) { int x; scanf("%d", &x); tab.push_back(x); } agg[0] = 1; for (int i = 0; i < n; ++i) { if (agg[i] == 0) { continue; } UL suma = 0; for (int j = i; j < n; ++j) { suma = MOD(suma + tab[j]); if (suma % 2 == 0) { agg[j+1] = MOD(agg[j+1] + agg[i]); } } } printf("%d\n", agg[n]); } |