@@ -12,7 +12,7 @@ void printSolution(vector<int>& solution) {
12
12
cout << " \n " ;
13
13
}
14
14
15
- void back (int step, int stop, vector<int >& domain, vector<int >& solution, unordered_set<int >& visited ) {
15
+ void back (int step, int stop, vector<int >& domain, vector<int >& solution, unordered_set<int >& used ) {
16
16
/* vom verifica o solutie atunci cand am adaugat deja N elemente in solutie,
17
17
adica step == stop */
18
18
if (step == stop) {
@@ -29,25 +29,25 @@ void back(int step, int stop, vector<int>& domain, vector<int>& solution, unorde
29
29
functia "check()" */
30
30
for (unsigned int i = 0 ; i < domain.size (); ++i) {
31
31
/* folosim elementul doar daca nu e vizitat inca */
32
- if (visited .find (domain[i]) == visited .end ()) {
32
+ if (used .find (domain[i]) == used .end ()) {
33
33
/* il marcam ca vizitat si taiem eventuale expansiuni nefolositoare
34
34
viitoare (ex: daca il adaug in solutie pe 3 nu voi mai avea
35
35
niciodata nevoie sa il mai adaug pe 3 in continuare) */
36
- visited .insert (domain[i]);
36
+ used .insert (domain[i]);
37
37
38
38
/* adaugam elementul curent in solutie pe pozitia pasului curent
39
39
(step) */
40
40
solution[step] = domain[i];
41
41
42
42
/* apelam recursiv backtracking pentru pasul urmator */
43
- back (step + 1 , stop, domain, solution, visited );
43
+ back (step + 1 , stop, domain, solution, used );
44
44
45
45
/* stergem vizitarea elementului curent (ex: pentru N = 3, dupa ce
46
46
la pasul "step = 0" l-am pus pe 1 pe prima pozitie in solutie si
47
47
am continuat recursiv pana am ajuns la solutiile {1, 2, 3} si
48
48
{1, 3, 2}, ne dorim sa il punem pe 2 pe prima pozitie in solutie si
49
49
sa continuam recursiv pentru a ajunge la solutiile {2, 1, 3} etc.) */
50
- visited .erase (domain[i]);
50
+ used .erase (domain[i]);
51
51
}
52
52
}
53
53
}
@@ -63,7 +63,7 @@ int main(int argc, char* argv[]) {
63
63
iar solutia este initializata cu un vector de n elemente (deoarece o permutare
64
64
contine n elemente) */
65
65
vector<int > domain (n), solution (n);
66
- unordered_set<int > visited ;
66
+ unordered_set<int > used ;
67
67
for (int i = 0 ; i < n; ++i) {
68
68
domain[i] = i + 1 ;
69
69
}
@@ -72,9 +72,9 @@ int main(int argc, char* argv[]) {
72
72
stop = n (stim ca vrem sa adaugam n elemente in solutie pentru ca o
73
73
permutare e alcatuita din n elemente), domain este vectorul de valori
74
74
posibile, solution este vectorul care simuleaza stiva pe care o vom
75
- umple, visited este un unordered_set (initial gol) in care retinem daca
75
+ umple, used este un unordered_set (initial gol) in care retinem daca
76
76
un element din domeniu se afla deja in solutia curenta la un anumit pas */
77
- back (0 , n, domain, solution, visited );
77
+ back (0 , n, domain, solution, used );
78
78
}
79
79
80
80
// Compile:
0 commit comments