二进制数递增
C++11 代码
#include <iostream>
using namespace std;
int main(int argc, char **argv)
{
int maxnum;
cin >> maxnum;
for (int i = 0; i != 1 << maxnum; ++i)
{
for (int j = 0; j != maxnum; ++j)
if (i & (1 << j))
cout << j + 1 << ' ';
cout << endl;
}
return EXIT_SUCCESS;
}