标签:void 传引用 cout item back turn return amp for
#include<iostream>
#include<vector>
using namespace std;
void solution(int i,vector<int> &nums,vector<int> &item,vector<vector<int> > &result) //传引用
{
if(i >= nums.size())
return ;
item.push_back(nums[i]);
result.push_back(item);
solution(i+1,nums,item,result);
item.pop_back();
solution(i+1,nums,item,result);
}
int main()
{
vector<int> nums;
nums.push_back(1);
nums.push_back(2);
nums.push_back(3);
vector<int> item;
vector<vector<int> >result;
int i = 0;
result.push_back(item); //将空集push进result
solution(i,nums,item,result);
for(int i = 0; i < (1<< nums.size()); i++)
{
if(result[i].size() == 0)
{
cout<<"[]";
}
for(int j = 0; j < result[i].size(); j++)
{
cout<<"["<<result[i][j]<<"]";
}
cout<<endl;
}
}
标签:void 传引用 cout item back turn return amp for
原文地址:https://blog.51cto.com/14472348/2471588