子集树:输出字符串子集
#include <iostream>
#include <vector>
#include <string>
using namespace std;
void func(string& str, int i, int length, vector<bool>& x)
{
if (i == length)
{
for (int j = 0; j < length; j++)
{
if (x[j])
{
cout << str[j] << " ";
}
}
cout << endl;
}
else
{
//选择输出
x[i] = true;
func(str, i + 1, length, x);
//不选择输出
x[i] = false;
func(str, i + 1, length, x);
}
}
int main()
{
string str("abc");
vector<bool> x(str.size());
func(str, 0, str.length(), x);
}