Repository navigation
Expand file tree
/
Copy path2.cpp
More file actions
65 lines (54 loc) · 1.63 KB
/
Copy path2.cpp
File metadata and controls
65 lines (54 loc) · 1.63 KB
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
#include <iostream>
using namespace std;
class byteland
{
public:
int citizens[5] = {1,2,3,4,5};
int enemy[5][5] = {{0,1,1,1,1},{1,0,0,1,1},{1,0,0,0,0},{1,1,0,0,0},{1,1,0,0,0}};//the matrix of enemy relationship
};
struct node
{
int level = 0;
int trace[5]={0};
node* left;
node* right;
node():left(NULL),right(NULL){}
};
bool conFunc(byteland BL, int rank){
if (BL.enemy[rank][rank + 1] == 1) return false;//当二者为仇敌时退出返回false
else return true;
};
bool bndFunc(byteland BL, node cuNode, int bestNum){
if (sumOfTrace(cuNode) + (sizeof(BL.citizens) - (cuNode.level + 1)) <= bestNum) return false;//当不会出现更优解时退出返回false
else return true;
};
int* solution(byteland BL){//完善该部分代码,需要做到1.bestNum的记录2.结束条件3.返回值对应的情况
node rootNode;
node cuNode;
int** bestTrc;//记录最佳路径
int cuNum = 0;//当前trace和
int bestNum = 0;//当前最优人数
while(true){
if (cuNode.level != sizeof(BL.citizens) && conFunc(BL,cuNode.level) && bndFunc(BL, cuNode, bestNum)){
cuNode.left = new node;
}
if (cuNode.level == sizeof(BL.citizens)) bestTrc = cuNode.trace;
}
};
int sumOfTrace(node Node){
int cuNum;
for(int i = 0; i < Node.level;i++){//计算当前trace上的和
cuNum += Node.trace[i];
}
return cuNum;
}
bndFunc(BL, cuNode, cuNum, bestNum)
int main()
{
node rootNode
node cuNode;
byteland myBL;
int bestRst = 0;
int cuNum = 0;
int reNum = 0;
}