Search
 
SCRIPT & CODE EXAMPLE
 

CPP

backtrack

#include <iostream>
using  namespace std;
 
int n, kq[11], dd[10];
 
void xuat()
{
    for (int j=1; j<=n; j++)
        cout<< kq[j]<<" ";
    cout << endl;
}
 
void backtrack(int i)
{
    if (i>n) xuat();
    for (int j=1; j<=n; j++)
        if (dd[j]==0)
        {
            dd[j]=1;
            kq[i]=j;
            backtrack(i+1);
            dd[j]=0;
        }
}
 
int main()
{
    cin >> n;
    for (int i=1; i<=9; i++)
        dd[i]=0;
    backtrack(1);
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ convert to assembly language 
Cpp :: how to print an array in cpp in single line 
Cpp :: c++ swap function 
Cpp :: c++ memset 
Cpp :: how to run cpp using gcc vscode 
Cpp :: how to find size of int in c++ 
Cpp :: __builtin_popcount long long 
Cpp :: web dev c++ 
Cpp :: cpp vector structure 
Cpp :: new in c++ 
Cpp :: c++ create function pointer 
Cpp :: minimum or maximum in array c++ 
Cpp :: heap allocated array in c ++ 
Cpp :: declare class c++ 
Cpp :: print all subsequences 
Cpp :: c++ custom printf 
Cpp :: cout in c++ 
Cpp :: C/C++ loop for 
Cpp :: how atan work c++ 
Cpp :: Write a C++ program to Computing Mean and Median Using Arrays 
Cpp :: coinPiles 
Cpp :: c++ get microseconds since epoch 
Cpp :: what is c++ 
Cpp :: Summation of Natural Number Sequence with c and c++. 
Cpp :: Calculating Function codeforces in c++ 
Cpp :: pimpl c++ 
Cpp :: c++ program that put a space in between characters 
Cpp :: find node from pos linkedlist c++ 
Cpp :: primtiive calculator in c++ 
Cpp :: beecrowd problem 1003 solution in c++ 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =