Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <map>
- using namespace std;
- const long long MOD = 1e9 + 7;
- int n;
- string to_binary(int x) {
- string res = "";
- while(x > 0) {
- res += (x % 2) + '0';
- x /= 2;
- }
- while((int) res.length() < n) {
- res += "0";
- }
- reverse(res.begin(), res.end());
- return res;
- }
- int main() {
- cin >> n;
- for(int bitmask = 0; bitmask < (1 << n); bitmask++) {
- for(int i = 0; i < n; i++) {
- if(bitmask & (1 << i)) {
- cout << i + 1 << " ";
- }
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment