#include <iostream> #include <vector> #include <map> #define MOD 1000000007 std::map<int *, int> full; int count(int *dd) { int *d = dd; long long res = 0LL; long long sum = 0LL; if(*d) { while(*d) { sum += *d; sum %= MOD; if(sum%2 == 0) { auto found = full.find(d+1); if(found != full.end()) { res += found->second; } else { res += count(d+1); } res %= MOD; } d++; } } else { res = 1; } full[dd] = res; return res; } int main() { int n, x; int *dd; std::vector<int> data; std::cin >> n; while(n--) { std::cin >> x; data.push_back(x); } dd = data.data(); std::cout << count(dd) << std::endl; 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 46 47 48 | #include <iostream> #include <vector> #include <map> #define MOD 1000000007 std::map<int *, int> full; int count(int *dd) { int *d = dd; long long res = 0LL; long long sum = 0LL; if(*d) { while(*d) { sum += *d; sum %= MOD; if(sum%2 == 0) { auto found = full.find(d+1); if(found != full.end()) { res += found->second; } else { res += count(d+1); } res %= MOD; } d++; } } else { res = 1; } full[dd] = res; return res; } int main() { int n, x; int *dd; std::vector<int> data; std::cin >> n; while(n--) { std::cin >> x; data.push_back(x); } dd = data.data(); std::cout << count(dd) << std::endl; return 0; } |