#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (int)n; i++) #define ST first #define ND second #define MP make_pair #define PB push_back typedef vector<int> VI; typedef pair<int, int> PII; typedef vector<PII> VPII; typedef set<int> SI; typedef long long LL; #ifdef DEBUG const bool debug = true; #else const bool debug = false; #endif // #define MULTI_TASK true const int INF = 1000 * 1000 * 1000; const LL INFLL = 1e18; const int MAKSN = 1000 * 1000 + 13; const LL MOD = (LL)(1e9 + 7); LL N, M, k, l, a, b, c, d, maks = 0; vector<LL> v; map<LL, LL> mapa; void zeruj() { v.clear(); } void readIn() { cin >> N; REP(i, N) { cin >> k; v.PB(k); } sort(v.begin(), v.end()); maks = v.back(); } LL pls(LL a, LL b) { return (a + b) % MOD; } void dodaj(LL val) { vector<pair<LL, long long>> to_add; for (auto it = mapa.rbegin(); it != mapa.rend(); it++) { if (it->first < val - 1) { break; } to_add.push_back({it->first + val, it->second}); } for (int i = 0; i < (int)to_add.size(); i++) { mapa[to_add[i].first] = pls(mapa[to_add[i].first], to_add[i].second); } } void solve() { mapa[0] = 1; for (int i = 0; i < N; i++) { dodaj(v[i]); } LL res = 0; for (auto x : mapa) { res = pls(res, x.second); } cout << res - 1 << "\n"; } int main() { ios_base::sync_with_stdio(0); #ifdef MULTI_TASK int test; cin >> test; while (test--) { #endif zeruj(); readIn(); solve(); #ifdef MULTI_TASK } #endif 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 | #include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (int)n; i++) #define ST first #define ND second #define MP make_pair #define PB push_back typedef vector<int> VI; typedef pair<int, int> PII; typedef vector<PII> VPII; typedef set<int> SI; typedef long long LL; #ifdef DEBUG const bool debug = true; #else const bool debug = false; #endif // #define MULTI_TASK true const int INF = 1000 * 1000 * 1000; const LL INFLL = 1e18; const int MAKSN = 1000 * 1000 + 13; const LL MOD = (LL)(1e9 + 7); LL N, M, k, l, a, b, c, d, maks = 0; vector<LL> v; map<LL, LL> mapa; void zeruj() { v.clear(); } void readIn() { cin >> N; REP(i, N) { cin >> k; v.PB(k); } sort(v.begin(), v.end()); maks = v.back(); } LL pls(LL a, LL b) { return (a + b) % MOD; } void dodaj(LL val) { vector<pair<LL, long long>> to_add; for (auto it = mapa.rbegin(); it != mapa.rend(); it++) { if (it->first < val - 1) { break; } to_add.push_back({it->first + val, it->second}); } for (int i = 0; i < (int)to_add.size(); i++) { mapa[to_add[i].first] = pls(mapa[to_add[i].first], to_add[i].second); } } void solve() { mapa[0] = 1; for (int i = 0; i < N; i++) { dodaj(v[i]); } LL res = 0; for (auto x : mapa) { res = pls(res, x.second); } cout << res - 1 << "\n"; } int main() { ios_base::sync_with_stdio(0); #ifdef MULTI_TASK int test; cin >> test; while (test--) { #endif zeruj(); readIn(); solve(); #ifdef MULTI_TASK } #endif return 0; } |