#include<bits/stdc++.h>
using namespace std;
int tab[5005];
long long dp[5005];
const int mod = 1e9+7;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int a;
cin>>a;
for(int x=0;x<a;x++)
cin>>tab[x];
dp[0] = 1;
sort(tab,tab+a);
for(int x=0;x<a;x++)
for(int y=5001;y>=tab[x]-1;y--)
dp[min(5001,y+tab[x])] = (dp[min(5001,y+tab[x])] + dp[y])%mod;
long long sum = 0;
for(int x=1;x<=5001;x++)
sum+=dp[x];
cout<<sum%mod;
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 | #include<bits/stdc++.h> using namespace std; int tab[5005]; long long dp[5005]; const int mod = 1e9+7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int a; cin>>a; for(int x=0;x<a;x++) cin>>tab[x]; dp[0] = 1; sort(tab,tab+a); for(int x=0;x<a;x++) for(int y=5001;y>=tab[x]-1;y--) dp[min(5001,y+tab[x])] = (dp[min(5001,y+tab[x])] + dp[y])%mod; long long sum = 0; for(int x=1;x<=5001;x++) sum+=dp[x]; cout<<sum%mod; return 0; } |
English