/
dfsboard.h
68 lines (56 loc) · 1.6 KB
/
dfsboard.h
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
64
65
66
67
68
#ifndef DFSBOARD_H
#define DFSBOARD_H
#include "board.h"
#include "unistd.h"
#include "cassert"
class DFSBoard;
struct Line{
line_type t;
int i;
int index;//including r and c
Line(){};
Line(line_type type, int i, int index): t(type), i(i), index(index){}
bool equals(line_type t, int i){
return (this->t == t) && (this-> i == i);
}
};
class LimitFiller{
public:
LimitFiller(){fillStart.clear();}
LimitFiller(vector<Limit>& limit):l(limit){ isInit = true;}
bool isInit;
vector<Limit> l;
vector<int> fillStart;
bool isInited(){return isInit;}
void setLimit(vector<Limit>& limits){l = (limits); isInit = true;}
void destroy(){isInit = false; fillStart.clear();}
bool getNextFillStart();
bool getNextFillStartbyFillStart();
bool isLimitLegal();
};
class DFSBoard: public Board{
public:
DFSBoard(Board& b): Board(b){//inherit
printBoard("before DFS");
limitFillers.resize(r+c);
backupBoards.resize(r+c);
isFilled.resize(r+c);
}
vector<bool> isFilled;
bool isFilledByDFS(line_type t, int i){if(t == ROW) return isFilled[i]; else return isFilled[r+i];}
vector< LimitFiller > limitFillers;
vector <vector<int> > lastfillStart;
vector<Board> backupBoards;
vector<Line> lineOrder;
void Restore(const Line&);
void Backup(const Line&);
void BackupBoard(Board &b);
void RestoreBoard(const Board &b);
//DFS with heuristic
void DoDFS();
void getLineWithMinBranch(int nowr, vector<Line>& lineOrder);
bool tryFillRowWithHeuristic(Line&);
void checkSolve();
bool tryFillRowbyFillStartHeuristic(const Line&, const vector<int>& fillStart);
};
#endif