#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int MOD=1e9+7;
const int M=5000;
int tab[5010];
int ans[M+10];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,w=0,i;
cin>>n;
for(i=1;i<=n;i++)
{
cin>>tab[i];
}
sort(tab+1,tab+n+1);
ans[0]=1;
for(i=1;i<=n;i++)
{
for(int j=M;j>=tab[i]-1;j--)
{
w=(w+ans[j])%MOD;
ans[min(j+tab[i],M)]=(ans[min(j+tab[i],M)]+ans[j])%MOD;
}
}
cout<<w<<"\n";
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 | #include<bits/stdc++.h> #define fi first #define se second using namespace std; const int MOD=1e9+7; const int M=5000; int tab[5010]; int ans[M+10]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n,w=0,i; cin>>n; for(i=1;i<=n;i++) { cin>>tab[i]; } sort(tab+1,tab+n+1); ans[0]=1; for(i=1;i<=n;i++) { for(int j=M;j>=tab[i]-1;j--) { w=(w+ans[j])%MOD; ans[min(j+tab[i],M)]=(ans[min(j+tab[i],M)]+ans[j])%MOD; } } cout<<w<<"\n"; return 0; } |
English