#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
long long suma = 1;
cin >> n;
vector<int> Cukierki(n);
for(int i=0; i<n; i++)
cin >> Cukierki[i];
sort(Cukierki.begin(), Cukierki.end());
int b=0;
int e=1;
if(Cukierki[0]>1)
{
cout << 0;
return 0;
}
vector<int> Sposoby(5000*n, 0);
Sposoby[1]=1;
Sposoby[0]=1;
for(int i=1; i<n; i++)
{
int temp;
for(int j=e; j>=b; j--)
{
if(j+1<Cukierki[i])
{
b=j;
break;
}else{
Sposoby[Cukierki[i]+j]+=Sposoby[j];
Sposoby[Cukierki[i]+j]%=1000000007;
suma+=Sposoby[j];
suma%=1000000007;
}
}
e+=Cukierki[i];
}
cout << suma;
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 | #include<iostream> #include<vector> #include<algorithm> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; long long suma = 1; cin >> n; vector<int> Cukierki(n); for(int i=0; i<n; i++) cin >> Cukierki[i]; sort(Cukierki.begin(), Cukierki.end()); int b=0; int e=1; if(Cukierki[0]>1) { cout << 0; return 0; } vector<int> Sposoby(5000*n, 0); Sposoby[1]=1; Sposoby[0]=1; for(int i=1; i<n; i++) { int temp; for(int j=e; j>=b; j--) { if(j+1<Cukierki[i]) { b=j; break; }else{ Sposoby[Cukierki[i]+j]+=Sposoby[j]; Sposoby[Cukierki[i]+j]%=1000000007; suma+=Sposoby[j]; suma%=1000000007; } } e+=Cukierki[i]; } cout << suma; return 0; } |
English