0

我有一个有趣的任务,我不知道从哪里开始。

想象一下,您有一组空间(大小都相同)和一组框(可变整数大小,1 或 2 或 3 个体积单位)。每个空间可以容纳 4 个单位的体积。给定一组随机的盒子,什么样的组合会留下最开放的空间(即最密集的包装)。

我不希望任何人为我编写我的代码,但我真的可以使用一些建议来解决这样的问题从哪里开始。任何人都可以帮忙吗?

我尝试列出所有排列,然后选择具有最多“开放空间”的排列,但它在计算上非常昂贵。如果这有所作为,我正在使用 C#。

代码有点冗长所以这里是伪代码

int [] boxes = new int[20] // I will be given an array of length 20 representing 20 boxes.
// the values of the boxes[] array will be random integers of either 1, 2 or 3
foreach (var v in boxes[]){boxes[v] = random(1 or 2 or 3)

//now i take the set of boxes and come up with all the permutations with a permutation function
int [,] permutearray = new int[20!,20] // each row is the index of a permutation, with the y value as the size.

//permutearray will be a set of numbers representing a possible combination of boxes like
{{1,3,2,2,1,2,3,4 ...},{3,1,2,3,2,1,1, ...}...}

//now check each row to see how many spaces it would take to contain the boxes in that order 
// do this using another function i call "fitcheck" on each row/column of permutearray
//fitcheck reports an array of numbers which represent the permutation index

int [] solutions = new [max_solutions]
solutions = fitcheck(permutearray)
4

0 回答 0