如題,題目說有多組解可以輸出任何一組根本是騙人的,遇到多組解的時候只能盡量把矩陣往左邊塞,
換句話說,分組的時候要嘛是
for (int j=i; j<i+d; j++) {
int temp = cost[i][j] + cost[j+1][i+d] + size[i-1]*size[j]*size[i+d];
if (temp <= cost[i][i+d]) { /* use <= instead of <, since the problem has no special judge... */
cost[i][i+d] = temp;
separator[i][i+d] = j;
}
}
要嘛就是
for (int j=i+d-1; j>=i; j++) {
int temp = cost[i][j] + cost[j+1][i+d] + size[i-1]*size[j]*size[i+d];
if (temp < cost[i][i+d]) { /* use <= instead of <, since the problem has no special judge... */
cost[i][i+d] = temp;
separator[i][i+d] = j;
}
}
但不可以是
for (int j=i; j<i+d; j++) {
int temp = cost[i][j] + cost[j+1][i+d] + size[i-1]*size[j]*size[i+d];
if (temp < cost[i][i+d]) {
cost[i][i+d] = temp;
separator[i][i+d] = j;
}
}