1
var sellingWood = function (m, n, prices) {2
let price = Array(n + 1)4
.map(() => Array(m + 1).fill(0));5
for (let [height, width, woodPrice] of prices) {6
price[width][height] = woodPrice;8
let memo = Array(n + 1)10
.map(() => Array(m + 1).fill(-1));13
function dfs(width, height) {14
if (width === 0 || height === 0) return 0;15
if (memo[width][height] !== -1) return memo[width][height];17
let ans = price[width][height];18
for (let h = 1; h <= Math.floor(height / 2); h++) {19
ans = Math.max(ans, dfs(width, h) + dfs(width, height - h));21
for (let w = 1; w <= Math.floor(width / 2); w++) {22
ans = Math.max(ans, dfs(w, height) + dfs(width - w, height));24
return (memo[width][height] = ans);