#include <bits/stdc++.h> #define ll long long #define st first #define nd second const ll mod=1e9+7; using namespace std; ll dp[25000001]; int main() { ios_base::sync_with_stdio(0); int n, maks=0; cin>>n; dp[0]=1; vector<int> v; for(int i=0; i<n; ++i){ int a; cin>>a; v.push_back(a); } sort(v.begin(), v.end()); for(int i=0; i<n; ++i){ int a=v[i]; queue<pair<int, ll> > kolejka; for(int j=a-1; j<=maks; ++j){ if(dp[j]){ kolejka.push({j+a, dp[j]}); } } while(!kolejka.empty()){ dp[kolejka.front().st]=(dp[kolejka.front().st]+kolejka.front().nd)%mod; maks=max(maks, kolejka.front().st); kolejka.pop(); } } ll ans=0; for(int i=1; i<=maks; ++i){ ans=(ans+dp[i])%mod; } cout<<ans; 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 | #include <bits/stdc++.h> #define ll long long #define st first #define nd second const ll mod=1e9+7; using namespace std; ll dp[25000001]; int main() { ios_base::sync_with_stdio(0); int n, maks=0; cin>>n; dp[0]=1; vector<int> v; for(int i=0; i<n; ++i){ int a; cin>>a; v.push_back(a); } sort(v.begin(), v.end()); for(int i=0; i<n; ++i){ int a=v[i]; queue<pair<int, ll> > kolejka; for(int j=a-1; j<=maks; ++j){ if(dp[j]){ kolejka.push({j+a, dp[j]}); } } while(!kolejka.empty()){ dp[kolejka.front().st]=(dp[kolejka.front().st]+kolejka.front().nd)%mod; maks=max(maks, kolejka.front().st); kolejka.pop(); } } ll ans=0; for(int i=1; i<=maks; ++i){ ans=(ans+dp[i])%mod; } cout<<ans; return 0; } |