-
Notifications
You must be signed in to change notification settings - Fork 0
/
Constraint_Satisfaction.cpp
76 lines (49 loc) · 1.01 KB
/
Constraint_Satisfaction.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include<vector>
#include<iostream>
#include<concepts>
#include<math.h>
#include "Utils.h"
/*
P2 - PCC104
*/
bool is_possible_var(std::vector<std::vector<int>>&dom, std::vector<int>& var, int element) {
if (var.size() == 0) {
return true;
}
else {
if (var.size() == 1 && element != var[0]) {
return false;
}
else {
if (var.size() == 3 && element < var[0]) {
return false;
}
else {
if (var.size() == 3 && element != var[2]){
return false;
}
}
}
}
return true;
}
bool solve_variavel(std::vector<std::vector<int>>& dom, std::vector<int>& var) {
if (var.size() == dom.size()) {
printSequence(var);
return true;
}
else {
for (int i = 0; i < dom[var.size()].size(); i++) {
if (is_possible_var(dom, var, dom[var.size()][i])){
var.push_back(dom[var.size()][i]);
solve_variavel(dom, var);
var.pop_back();
}
}
return false;
}
}
void variavel(std::vector<std::vector<int>>& dom) {
std::vector<int> var({});
solve_variavel(dom, var);
}