我了解 Box Stacking 问题的动态编程解决方案,它试图找到可以由一组给定的盒子形成的堆栈的最大可能长度,可以在任何方向上旋转,这样下面的盒子总是更小与堆栈中较高的盒子相比,其宽度和长度。
但是,我无法理解为什么每个盒子只需要 3 个方向。根据我的说法,方向的数量应该是 6。也就是说,对于作为高度的三个维度中的每一个,你应该有两种组合。
在线资源显示以下作为创建原始框的三个方向(2 个旋转)的方法。
/* Create an array of all rotations of given boxes
For example, for a box {1, 2, 3}, we consider three
instances{{1, 2, 3}, {2, 1, 3}, {3, 1, 2}} */
Box rot[3*n];
int index = 0;
for (int i = 0; i < n; i++)
{
// Copy the original box
rot[index] = arr[i];
index++;
// First rotation of box
rot[index].h = arr[i].w;
rot[index].d = max(arr[i].h, arr[i].d);
rot[index].w = min(arr[i].h, arr[i].d);
index++;
// Second rotation of box
rot[index].h = arr[i].d;
rot[index].d = max(arr[i].h, arr[i].w);
rot[index].w = min(arr[i].h, arr[i].w);
index++;
}
因此,例如,对于框 {1,2,3},三个方向将是
1 2 3
2 1 3
3 1 2
但在我看来,方向应该是
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
我知道我额外的三个组合是由于它们之间的长度和宽度交替保持高度相同。因此,尽管我认为 1 2 3 和 1 3 2 不同,但原始算法认为它们是相同的。
但是,我觉得,在这个问题中,h,l,w 和 h,w,l 应该被视为两个独立的方向,因为一个盒子说,l=3,w=4,h=5 可以堆叠在一个盒子上方比如说,l=4,w=5 ,h=6,但不在盒子上方l=5,w=4 ,h=6