#include <iostream>
using namespace std;
int main(){
int array [] = { 2,10,4,5,7,1,3,9,6,8,11,12};
int length=10;
int requiredSum=16;
int sum=0;
// 循环子集
for (unsigned int i=1; i<(1<<length); ++i,sum=0) {
for (unsigned int k=0; k<32; ++k)
if ((i&(1<<k)))//检查是否含有第K个元素
sum += array[k];
if (sum==requiredSum){
for (unsigned int k=0; k<32; ++k )
if ((i&(1<<k)))
cout << array[k] << ' ';
cout << endl;
}
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKXsKCWludCBhcnJheSBbXSA9IHsgMiwxMCw0LDUsNywxLDMsOSw2LDgsMTEsMTJ9OwoJaW50IGxlbmd0aD0xMDsKICAgICAgICBpbnQgcmVxdWlyZWRTdW09MTY7CiAgICAgICAgaW50IHN1bT0wOwogICAgICAgIC8vIOW+queOr+WtkOmbhgoJZm9yICh1bnNpZ25lZCBpbnQgaT0xOyBpPCgxPDxsZW5ndGgpOyArK2ksc3VtPTApIHsKCQlmb3IgKHVuc2lnbmVkIGludCBrPTA7IGs8MzI7ICsraykKCQkJaWYgKChpJigxPDxrKSkpLy/mo4Dmn6XmmK/lkKblkKvmnInnrKxL5Liq5YWD57SgCgkJCQlzdW0gKz0gYXJyYXlba107CgkJaWYgKHN1bT09cmVxdWlyZWRTdW0pewoJCQlmb3IgKHVuc2lnbmVkIGludCBrPTA7IGs8MzI7ICsrayApCgkJCQlpZiAoKGkmKDE8PGspKSkKCQkJCQljb3V0IDw8IGFycmF5W2tdIDw8ICcgJzsgCgkJCWNvdXQgPDwgZW5kbDsKCQl9Cgl9Cn0g