Tap here to switch tabs
Problem
Submissions

Problem: Selling Pieces of Wood

Try to solve the Selling Pieces of Wood problem.

Statement

You are given two integers m and n representing the dimensions of a rectangular piece of wood of height m and width n. You are also given a 22D integer array prices, where prices[i] = [hi,wi,pricei][h_i, w_i, price_i] indicates that a rectangular piece of wood of height h_i and width w_i can be sold for price_i money.

You can perform any number of horizontal or vertical cuts on a piece of wood to divide it into two smaller rectangular pieces. Each resulting piece can subsequently be cut further in the same manner. Any piece of wood with dimensions matching an entry in prices can be sold. A piece can also be left uncut or unsold.

Return the maximum amount of money that can be earned after cutting and selling the pieces.

Note: Pieces of wood cannot be rotated. A piece of wood of height h and width w is not equivalent to a piece of wood of height w and width h unless h equals w.

Constraints:

  • 1≤1 \leq m, n ≤200\leq 200

  • 1≤1 \leq prices.length ≤2imes104\leq 2 imes 10^4

  • prices[i].length =3= 3

  • 1≤1 \leq h_i ≤\leq m

  • 1≤1 \leq w_i ≤\leq n

  • 1≤1 \leq price_i ≤106\leq 10^6

  • All the shapes of wood (h_i, w_i) are pairwise distinct.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Selling Pieces of Wood

Try to solve the Selling Pieces of Wood problem.

Statement

You are given two integers m and n representing the dimensions of a rectangular piece of wood of height m and width n. You are also given a 22D integer array prices, where prices[i] = [hi,wi,pricei][h_i, w_i, price_i] indicates that a rectangular piece of wood of height h_i and width w_i can be sold for price_i money.

You can perform any number of horizontal or vertical cuts on a piece of wood to divide it into two smaller rectangular pieces. Each resulting piece can subsequently be cut further in the same manner. Any piece of wood with dimensions matching an entry in prices can be sold. A piece can also be left uncut or unsold.

Return the maximum amount of money that can be earned after cutting and selling the pieces.

Note: Pieces of wood cannot be rotated. A piece of wood of height h and width w is not equivalent to a piece of wood of height w and width h unless h equals w.

Constraints:

  • 1≤1 \leq m, n ≤200\leq 200

  • 1≤1 \leq prices.length ≤2imes104\leq 2 imes 10^4

  • prices[i].length =3= 3

  • 1≤1 \leq h_i ≤\leq m

  • 1≤1 \leq w_i ≤\leq n

  • 1≤1 \leq price_i ≤106\leq 10^6

  • All the shapes of wood (h_i, w_i) are pairwise distinct.