Skip to content

Instantly share code, notes, and snippets.

@sealddr
Last active October 7, 2017 02:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sealddr/c98b90effc7bcee0aac3221a995f7486 to your computer and use it in GitHub Desktop.
Save sealddr/c98b90effc7bcee0aac3221a995f7486 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int main(void){
// Here your code !
int n=4;
int a[]={1,2,4,7};
int k=15;
unsigned int maxbmap=(1 << n);
for(int bmap=0; bmap<maxbmap; bmap++){
int subsetsum=0;
for(int j=0; j<n; j++){
if(0 != (bmap & (1 << j))){
subsetsum += a[j];
}
}
if(k == subsetsum){
std::cout << "Yes" << std::endl;
return 0;
}
}
std::cout << "No" << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment