#include <iostream>
#include <string>
#include <vector>
using ULL = unsigned long long;
struct Node
{
ULL count;
ULL sum;
};
std::ostream &operator<<(std::ostream &os, Node const &node)
{
os << "(" << node.count << ":" << node.sum << ")";
return os;
}
std::ostream &operator<<(std::ostream &os, std::vector<Node> const &nodes)
{
for (auto const &node : nodes)
std::cout << node << " ";
std::cout << std::endl;
return os;
}
ULL modulo(ULL x)
{
return x % 1000000007;
}
bool isEven(ULL x)
{
return x % 2 == 0;
}
ULL brute(std::vector<ULL> const &numbers)
{
std::vector<std::vector<Node>> t;
t.reserve(numbers.size());
ULL first = isEven(numbers.front()) ? 1 : 0;
t.push_back({{first, numbers.front()}, {first, numbers.front()}});
for (int i = 1; i < numbers.size(); ++i)
{
// std::cout << i << std::endl;
t.emplace_back();
ULL currentCount = 0;
ULL tmpSum = numbers.at(i);
ULL tmpCount = isEven(tmpSum) ? t[i - 1][i].count : 0;
Node tmpNode{tmpCount, tmpSum};
currentCount += tmpCount;
t[i].push_back(tmpNode);
for (int j = 1; j < i; ++j)
{
tmpSum = modulo(t[i].back().sum + t[i - j][0].sum);
tmpCount = isEven(tmpSum) ? t[i - j-1].back().count : 0;
t[i].push_back({tmpCount, tmpSum});
currentCount += tmpCount;
}
tmpSum = modulo(numbers.at(i) + t[i-1].back().sum);
tmpCount = isEven(tmpSum) ? 1 : 0;
currentCount += tmpCount;
t[i].push_back({tmpCount, tmpSum});
t[i].push_back({modulo(currentCount), t[i].back().sum});
}
// for (auto const& row : t)
// std::cout << row;
return t.back().back().count;
}
ULL solve(std::vector<ULL> const &numbers)
{
return 0;
}
int main()
{
int n;
std::cin >> n;
std::vector<ULL> numbers;
numbers.reserve(n);
for (int i = 0; i < n; ++i)
{
ULL tmp;
std::cin >> tmp;
numbers.push_back(tmp);
}
std::cout << brute(numbers) << 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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | #include <iostream> #include <string> #include <vector> using ULL = unsigned long long; struct Node { ULL count; ULL sum; }; std::ostream &operator<<(std::ostream &os, Node const &node) { os << "(" << node.count << ":" << node.sum << ")"; return os; } std::ostream &operator<<(std::ostream &os, std::vector<Node> const &nodes) { for (auto const &node : nodes) std::cout << node << " "; std::cout << std::endl; return os; } ULL modulo(ULL x) { return x % 1000000007; } bool isEven(ULL x) { return x % 2 == 0; } ULL brute(std::vector<ULL> const &numbers) { std::vector<std::vector<Node>> t; t.reserve(numbers.size()); ULL first = isEven(numbers.front()) ? 1 : 0; t.push_back({{first, numbers.front()}, {first, numbers.front()}}); for (int i = 1; i < numbers.size(); ++i) { // std::cout << i << std::endl; t.emplace_back(); ULL currentCount = 0; ULL tmpSum = numbers.at(i); ULL tmpCount = isEven(tmpSum) ? t[i - 1][i].count : 0; Node tmpNode{tmpCount, tmpSum}; currentCount += tmpCount; t[i].push_back(tmpNode); for (int j = 1; j < i; ++j) { tmpSum = modulo(t[i].back().sum + t[i - j][0].sum); tmpCount = isEven(tmpSum) ? t[i - j-1].back().count : 0; t[i].push_back({tmpCount, tmpSum}); currentCount += tmpCount; } tmpSum = modulo(numbers.at(i) + t[i-1].back().sum); tmpCount = isEven(tmpSum) ? 1 : 0; currentCount += tmpCount; t[i].push_back({tmpCount, tmpSum}); t[i].push_back({modulo(currentCount), t[i].back().sum}); } // for (auto const& row : t) // std::cout << row; return t.back().back().count; } ULL solve(std::vector<ULL> const &numbers) { return 0; } int main() { int n; std::cin >> n; std::vector<ULL> numbers; numbers.reserve(n); for (int i = 0; i < n; ++i) { ULL tmp; std::cin >> tmp; numbers.push_back(tmp); } std::cout << brute(numbers) << std::endl; return 0; } |
English