bestnode.java
来自「一个简单的货郎担问题」· Java 代码 · 共 39 行
JAVA
39 行
public class BestNode {
int[][] m;
int n;
int node, cost;
BestNode(int[][] m, int n) {
this.m = m;
this.n = n;
}
int bestNode(int i, boolean[] b) {
BestWay bw = new BestWay(m, n);
boolean flag = true;
int j = 0;
for (j = 0; j < n; j++) {
flag &= b[j];
}
if (flag){
return i;
}
int min = 1000;
for (j = 1; j < n; j++) {
if (b[j] == true)
continue;
b[j] = true;
cost = m[i][j] + bw.bestWay(j, b);
if (min > cost) {
min = cost;
node = j;
}
b[j] = false;
}
return node;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?