区域内的排列量?

Amount of permutations inside an area?

我有以下情况:

这是我的问题:我如何计算有多少可能的选择 我必须:

  1. 计算元素的行/列跨度(高度/宽度):对于 6 的区域,不同的选项可以是例如 6x1、1x6、3x2 和 2x3 .. 必要条件 就是元素需要是正方形或者长方形,所以f.e。不是 U 形或 T 形占据单元格中的网格。这就是我挣扎的地方! 那么我应该像 if 案例那样做案例吗?我想有一种更有效的方法可以做到这一点!什么是条件?

  2. 将这些元素放在区域内

我正在 java 和 javafx 编程。

到目前为止,我尝试了以下方法来计算跨度 /height/width:

    int NumberRow = 6; 
    int NumberColum = 6;
    int columspan;
    int rowspan;
    int area = 6;
    if (area / NumberRow == 1) {
       columspan = 1;
       rowspan = area;}

    if  (area/NumberColum== 1) {
      columspan = area;
      rowspan = 1;
    }
    // if area modulo NumberColum or NumberRow == 0 it's an multiple..
    if  (area % NumberColum == 0 ) {
      ???? --> what would make sense here ? 

    }


    VBox v = new VBox();
    v.getChildren().addAll(h1, t, image);
    grid.add(v, colum, row, columspan, rowspan);

元素数组可以按大小递减排序。

由于要填满整个区域,可以从上到下,从左到右填满。

对于每个区域元素,都必须遍历可能的形式;对于 6: (1, 6), (6, 1), (2, 3), (3, 2):寻找因子对。

带回溯的递归;递归看起来像:

if (free space == 0)
    print success with placements
    ++solution count
    return;
for every candidate:
    if (candidate fits here)
        place candidate here
            recurse (candidates without candidate)
        remove candidate here

我不会破坏摆在你面前的令人费解的谜题。