#include "bits/stdc++.h" using namespace std; template <class A, class B> ostream& operator<<(ostream &os, pair<A, B> p) { return os << '{' << p.first << ", " << p.second << '}'; } template <class T> ostream& operator<<(ostream &os, vector<T> v) { os << '{'; for (T i : v) os << i << ", "; return os << '}'; } #ifdef DEBUG #define D(x...) x #else #define D(x...) #endif #define LN(x) D(cerr << #x << ": " << x << ' ') #define LOG(x) D(cerr << #x << ": " << x << '\n') #define MES(x) D(cerr << x << ' ') #define MESL(x) D(cerr << x << '\n') typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<bool> vb; typedef pair<int, int> pii; #define EB emplace_back #define PB pop_back #define fi first #define se second #define FOR(i, a, b) for (int i = (a); i <= (b); ++i) #define REP(i, n) FOR(i, 0, (n) - 1) // Ignacy Boehlke constexpr int MOD = 1000000007; constexpr int MAX = 4999; #define CAP(x) min(x, MAX) int add(int a, int b) { return (a + b) % MOD; } int main() { int n; scanf("%d", &n); vi vec(n + 1); FOR(i, 1, n) scanf("%d", &vec[i]); sort(vec.begin(), vec.end()); LOG(vec); vi dp(MAX + 1); dp[0] = 1; FOR(i, 1, n) { int x; for(int j = MAX; j >= vec[i] - 1; --j) x = CAP(j + vec[i]), dp[x] = add(dp[x], dp[j]); //LOG(dp); } int res = 0; FOR(i, 1, MAX) res = add(res, dp[i]); printf("%d\n", res); }
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 | #include "bits/stdc++.h" using namespace std; template <class A, class B> ostream& operator<<(ostream &os, pair<A, B> p) { return os << '{' << p.first << ", " << p.second << '}'; } template <class T> ostream& operator<<(ostream &os, vector<T> v) { os << '{'; for (T i : v) os << i << ", "; return os << '}'; } #ifdef DEBUG #define D(x...) x #else #define D(x...) #endif #define LN(x) D(cerr << #x << ": " << x << ' ') #define LOG(x) D(cerr << #x << ": " << x << '\n') #define MES(x) D(cerr << x << ' ') #define MESL(x) D(cerr << x << '\n') typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<bool> vb; typedef pair<int, int> pii; #define EB emplace_back #define PB pop_back #define fi first #define se second #define FOR(i, a, b) for (int i = (a); i <= (b); ++i) #define REP(i, n) FOR(i, 0, (n) - 1) // Ignacy Boehlke constexpr int MOD = 1000000007; constexpr int MAX = 4999; #define CAP(x) min(x, MAX) int add(int a, int b) { return (a + b) % MOD; } int main() { int n; scanf("%d", &n); vi vec(n + 1); FOR(i, 1, n) scanf("%d", &vec[i]); sort(vec.begin(), vec.end()); LOG(vec); vi dp(MAX + 1); dp[0] = 1; FOR(i, 1, n) { int x; for(int j = MAX; j >= vec[i] - 1; --j) x = CAP(j + vec[i]), dp[x] = add(dp[x], dp[j]); //LOG(dp); } int res = 0; FOR(i, 1, MAX) res = add(res, dp[i]); printf("%d\n", res); } |