Created
December 28, 2017 08:30
-
-
Save thinkphp/ba98ff79adc5df7b1aefff3171343000 to your computer and use it in GitHub Desktop.
Generating the subsets of a set.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <vector> | |
#define FIN "submultimi.in" | |
#define FOUT "submultimi.out" | |
using namespace std; | |
int main() { | |
int n; | |
ifstream fin(FIN); | |
ofstream fout(FOUT); | |
fin>>n; | |
vector<int> stack; | |
stack.push_back( 1 ); | |
while(!stack.empty()) { | |
for(vector<int>::size_type i = 0; i < stack.size(); ++i) fout<<stack[i]<<" "; | |
fout<<endl; | |
if(stack.back() < n) { | |
stack.push_back(stack.back() + 1); | |
} else { | |
stack.pop_back(); | |
if(!stack.empty()) stack.back()++; | |
} | |
} | |
return(0); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment