#include using namespace std; //Sinh cau hinh moi tu cau hinh dang co void next_config(int x[], int n, int i) { x[i] = 1; i++; while (i <= n) { //Dat x[i+1], ..., x[n] = 0 x[i] = 0; i++; } } //Hien thi mot cau hinh void view_config(int x[], int n) { for (int i = 1; i <= n; i++) cout << x[i]; cout << endl; } //Liet ke cac cau hinh void listing_configs(int n) { int i; //x[n + 1] = { 0 }; int x[n + 1]; for (i = 0; i <= n; i++) x[i] = 0; //Cau hinh dau tien {00...0} do { view_config(x, n); //In mot cau hinh i = n; while (i > 0 && x[i] == 1) { i--; } if (i > 0) { //Chua phai cau hinh cuoi next_config(x, n, i); } } while (i > 0); } int main() { int n; cout << "Nhap n: "; cin >> n; listing_configs(n); return 0; }