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;
- int power_of_2 = (1 << n);
- for(int i = 0; i < power_of_2; i++) {
- string s = to_binary(i);
- for(int j = 0; j < s.length(); j++) {
- if(s[j] == '1') {
- cout << j + 1 << " ";
- }
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment