binary n bit, k bit is "on" state
not my codeManhDX
c_cpp
3 years ago
952 B
5
Indexable
#include<bits/stdc++.h> using namespace std; int n, k, check; vector<vector<int>> res; vector<int> a; void khoi_tao(vector<int> &x) { for ( int i=0 ; i<n ; i++ ) { x.push_back(0); } } bool check1() { int cnt=0; for (int i=0 ; i<=n-1 ; i++ ) { if ( a[i]==1 ) cnt++; } if (cnt==k) return true; else return false; } void sinh() { int i=n-1; while (i>=0 && a[i]==1) { a[i]=0; --i; } if (i==-1) { check=0; } else { a[i]=1; } check1(); } int main() { cin>>n>>k; khoi_tao(a); check=1; while (check) { if (check1()==true) res.push_back(a); sinh(); } for (vector<int> y : res) { for (int x : y) { cout << x; } cout << endl; } }
Editor is loading...