#include<bits/stdc++.h>
using namespace std;
const int P = 1000*1000*1000+7;
int main()
{
ios::sync_with_stdio(0);
//freopen("cuk00e.in","r",stdin);
int n;
cin >> n;
vector<int> a(n);
for(int i=0; i<n; ++i) cin >> a[i];
sort(a.begin(), a.end());
map<int,int> mv;
mv[0]=1;
for(int i=0; i<n; ++i)
{
// przetwarzamy a[i]; nowe elementy wrzucamy do w;
vector<pair<int,int>> w;
auto it0 = mv.lower_bound(a[i]-1);
for(auto it=it0; it!=mv.end(); ++it)
{
w.push_back(make_pair(a[i] + it->first, it->second));
}
// dodaj w do v
for(int j=0; j<w.size(); ++j)
{
int val = (mv[w[j].first] + w[j].second)%P;
mv[w[j].first] = val;
}
}
int res = -1;
for(auto it = mv.begin(); it!=mv.end(); ++it)
{
res += it->second;
res %= P;
}
cout << res << endl;
}
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 | #include<bits/stdc++.h> using namespace std; const int P = 1000*1000*1000+7; int main() { ios::sync_with_stdio(0); //freopen("cuk00e.in","r",stdin); int n; cin >> n; vector<int> a(n); for(int i=0; i<n; ++i) cin >> a[i]; sort(a.begin(), a.end()); map<int,int> mv; mv[0]=1; for(int i=0; i<n; ++i) { // przetwarzamy a[i]; nowe elementy wrzucamy do w; vector<pair<int,int>> w; auto it0 = mv.lower_bound(a[i]-1); for(auto it=it0; it!=mv.end(); ++it) { w.push_back(make_pair(a[i] + it->first, it->second)); } // dodaj w do v for(int j=0; j<w.size(); ++j) { int val = (mv[w[j].first] + w[j].second)%P; mv[w[j].first] = val; } } int res = -1; for(auto it = mv.begin(); it!=mv.end(); ++it) { res += it->second; res %= P; } cout << res << endl; } |
English