fork download
  1. #include<bits/stdc++.h>
  2. #define int long long
  3. using namespace std;
  4. signed main(){
  5. ios::sync_with_stdio(false); cin.tie(nullptr);
  6. int n,s,ans=0; cin>>n>>s;
  7. int a[n]; for(int i=0;i<n;i++) cin>>a[i];
  8.  
  9. for(int i=1;i<(1<<n);i++){ // the empty subset is not counted so i=1
  10. int sum=0;
  11. for(int j=0;j<n;j++){
  12. if( (i>>j)&1 ) sum+=a[j];
  13. }
  14. if(sum<=s) ans++;
  15. }
  16. cout<<ans;
  17. }
  18.  
Success #stdin #stdout 0.01s 5288KB
stdin
6 4 
7 2 6 5 1 4
stdout
4