Back
Sinh_Hoan_Vi_Quay_Lui.cpp
Save
// Sinh_Hoan_Vi_Quay_Lui.cpp #include
using namespace std; int n; int *x; bool *dd; void Show(int *x) { for (int i = 1; i <= n; i++) { cout << x[i]; } cout << endl; } int Try(int k) { for (int i = 0; i <= n; i++) { if (!dd[i]) { x[k] = i; if (k == n) { Show(x); } else { dd[i] = true; Try(k + 1); dd[i] = false; } } } } int main() { cout << "Nhap n: "; cin >> n; x = new int(n + 1); dd = new bool(n + 1); Try(1); return 0; }