#include <bits/stdc++.h> #define REP(i,n) for(int _n=(n), i=0;i<_n;++i) #define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i) #define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i) using std::vector; void init_io() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); } template<unsigned MOD> class Modulo { public: Modulo(unsigned x=0):v(x) {} unsigned get() const { return v; } Modulo operator+(Modulo b) const { unsigned res = v+b.v; if (res >= MOD) res -= MOD; return res; } void operator+=(Modulo b) { *this = *this + b; } Modulo operator-(Modulo b) const { return *this + Modulo(MOD-b.v); } void operator-=(Modulo b) { *this = *this - b; } private: unsigned v; }; using Mod = Modulo<1'000'000'007>; vector<int> boxes; void read_input() { size_t n; std::cin >> n; boxes.reserve(n); REP(i,n) { int x; std::cin >> x; boxes.push_back(x); } std::sort(boxes.begin(), boxes.end()); } Mod calc_ways() { int range = std::max(2, boxes.back()); std::vector<Mod> ways_at_least(range); std::vector<Mod> new_ways_at_least(range); ways_at_least[0] = 1; for(int box : boxes) { // need at least box-1 previously REP(x, range) { new_ways_at_least[x] = ways_at_least[x] + ways_at_least[std::max(box-1, x-box)]; } ways_at_least.swap(new_ways_at_least); } return ways_at_least[1]; } int main() { init_io(); read_input(); Mod res = calc_ways(); std::cout << res.get() << "\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 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 | #include <bits/stdc++.h> #define REP(i,n) for(int _n=(n), i=0;i<_n;++i) #define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i) #define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i) using std::vector; void init_io() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); } template<unsigned MOD> class Modulo { public: Modulo(unsigned x=0):v(x) {} unsigned get() const { return v; } Modulo operator+(Modulo b) const { unsigned res = v+b.v; if (res >= MOD) res -= MOD; return res; } void operator+=(Modulo b) { *this = *this + b; } Modulo operator-(Modulo b) const { return *this + Modulo(MOD-b.v); } void operator-=(Modulo b) { *this = *this - b; } private: unsigned v; }; using Mod = Modulo<1'000'000'007>; vector<int> boxes; void read_input() { size_t n; std::cin >> n; boxes.reserve(n); REP(i,n) { int x; std::cin >> x; boxes.push_back(x); } std::sort(boxes.begin(), boxes.end()); } Mod calc_ways() { int range = std::max(2, boxes.back()); std::vector<Mod> ways_at_least(range); std::vector<Mod> new_ways_at_least(range); ways_at_least[0] = 1; for(int box : boxes) { // need at least box-1 previously REP(x, range) { new_ways_at_least[x] = ways_at_least[x] + ways_at_least[std::max(box-1, x-box)]; } ways_at_least.swap(new_ways_at_least); } return ways_at_least[1]; } int main() { init_io(); read_input(); Mod res = calc_ways(); std::cout << res.get() << "\n"; } |