Skip to content

Instantly share code, notes, and snippets.

@sealddr
Last active Oct 7, 2017
Embed
What would you like to do?
#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