#include <iostream> #include <vector> #include <string> #include <map> using namespace std; const int pier = 1000000007; bool mopadulo(long long l) { if (((l%pier)%2)==0) return true; else return false; } long long l_podz(vector<long long>::iterator Vp, vector<long long>::iterator Vk) { int rozm = Vk-Vp; if (rozm == 1) { return 1; } long long ans = 0; long long x = (*Vp); for (int i = 1; i < rozm; i++) { if(mopadulo(*(Vp+i)-x) ) { ans += l_podz((Vp+i), Vk); ans = ans%pier; } } return ans; } int main() { int n, t; cin>>n; vector <int> a(n); vector <long long> indsum (n+1); for (int i = 0; i < n; i++) { cin >>a[i]; indsum[i+1]=indsum[i]+a[i]; } cout << l_podz(indsum.begin(), indsum.end()); }
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 49 50 51 52 53 | #include <iostream> #include <vector> #include <string> #include <map> using namespace std; const int pier = 1000000007; bool mopadulo(long long l) { if (((l%pier)%2)==0) return true; else return false; } long long l_podz(vector<long long>::iterator Vp, vector<long long>::iterator Vk) { int rozm = Vk-Vp; if (rozm == 1) { return 1; } long long ans = 0; long long x = (*Vp); for (int i = 1; i < rozm; i++) { if(mopadulo(*(Vp+i)-x) ) { ans += l_podz((Vp+i), Vk); ans = ans%pier; } } return ans; } int main() { int n, t; cin>>n; vector <int> a(n); vector <long long> indsum (n+1); for (int i = 0; i < n; i++) { cin >>a[i]; indsum[i+1]=indsum[i]+a[i]; } cout << l_podz(indsum.begin(), indsum.end()); } |