#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
long long wynik = 0;
long long mod = 1000000007;
void calc (long long suma, long long i, vector <int> &A){
if(suma<A[i]-1) return;
wynik++;
wynik = wynik%mod;
if(i==A.size()-1) return;
calc(suma,i+1, A);
calc(suma+A[i],i+1,A);
}
int main(){
cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false);
int n; cin >> n;
vector<int> A(n);
for(int i=0;i<n;i++)cin >> A[i];
sort(A.begin(),A.end());
calc(0,0, A);
cout << wynik << '\n';
}
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 <iostream> #include <vector> #include <algorithm> using namespace std; long long wynik = 0; long long mod = 1000000007; void calc (long long suma, long long i, vector <int> &A){ if(suma<A[i]-1) return; wynik++; wynik = wynik%mod; if(i==A.size()-1) return; calc(suma,i+1, A); calc(suma+A[i],i+1,A); } int main(){ cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false); int n; cin >> n; vector<int> A(n); for(int i=0;i<n;i++)cin >> A[i]; sort(A.begin(),A.end()); calc(0,0, A); cout << wynik << '\n'; } |
English