How to modify grid layout algorithm so it puts 2, 4, 6, 8, etc. fewer elements at the end rows?

Building off @trincot’s answer to How to chunk array into nice grid of rows and columns, where columns always line up (all rows are even, or all are odd)? how can we modify the goal slightly to allow for trailing rows to still be odd (if the starting rows were odd), or still be even (if starting rows were even), but instead of only allowing “2 fewer” elements in each trailing row, like this:

x x x x x x x x
  x x x x x x
    x x x x
      x x

(Here, each row has 2 fewer than the last). Instead of the 2-fewer approach, what if we just made it so it could have 2, 4, 6, 8 (multiple of 2) fewer? So something like this would be acceptible:

x x x x x x x x
x x x x x x x x
    x x x x

Or even this:

x x x x x x x x
x x x x x x x x
      x x

How could you modify the linked algorithm (copied here), to make that possible?

function distribute(length, maxColumns) {

    function recur(dp, length, width) {
        if (length == 0) return [];
        if (length < width - 2 || width <= 0) return false;
        if (dp[width].has(length)) return false;
        dp[width].add(length);
        for (let i = 0; i < 2; i++) {
            let result = recur(dp, length - width, width);
            if (result) return [width, ...result];
            width -= 2;
        }
        return false;
    }
    
    
    if (length <= maxColumns) return [length];
    const dec = 2 - length % 2;
    maxColumns -= maxColumns % dec;
    const dp = Array.from({length: maxColumns + 1}, () => new Set());
    for (let width = maxColumns; width > 0; width -= dec) {
        const result = recur(dp, length - width, width);
        if (result) return [width, ...result];
    }
    return false;
}

const tests = [
    [1, 5],
    [6, 5],
    [7, 6],
    [8, 6],
    [9, 6],
    [10, 6],
    [11, 6],
    [12, 6],
    [13, 6],
    [14, 6],
    [17, 7],
    [17, 6],
    [211, 16]
];

for (const [length, maxColumns] of tests) {
    const result = distribute(length, maxColumns);
    console.log(length, maxColumns, JSON.stringify(result));
}