#include
#include
using namespace std;
vector > result;
int cnt;
void solution(vector nums)
{
int num=1;
cnt = (1 << nums.size());
for(int i = 0; i < cnt; i++)
{
vector item;
for(int j = 0; j < nums.size(); j++)
{
if(i & (1 << j))
{
item.push_back(nums[j]);
}
}
result.push_back(item);
}
}
int main()
{
vector nums;
nums.push_back(1);
nums.push_back(2);
nums.push_back(3);
solution(nums);
for(int i = 0; i < cnt; i++)
{
if(result[i].size() == 0)
{
cout<<"[]";
}
for(int j = 0; j < result[i].size(); j++)
{
cout<<"["<
新闻标题:二进制求子集
文章来源:
http://cdweb.net/article/pjjgic.html