Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <vector>
- #include <cmath>
- using namespace std;
- const int maxn = 1e6;
- const int INF = 2e9;
- typedef long long ll;
- int n;
- string to_binary(int x) {
- string res = "";
- while(x > 0) {
- res += (x % 2) + '0';
- x /= 2;
- }
- while((int) res.size() < n) {
- res += "0";
- }
- reverse(res.begin(), res.end());
- return res;
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin >> n;
- int power_of_2 = (1 << n);
- vector<int> v = {1, 2, 3};
- for(int i = 0; i < power_of_2; i++) {
- string s = to_binary(i);
- for(int j = 0; j < (int) s.size(); j++) {
- if(s[j] == '1') {
- cout << v[j] << " ";
- }
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment