Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost for Cutting Cake I

Try to solve the Minimum Cost for Cutting Cake I problem.

Statement

You are given two integers m and n representing a cake of size m ×\times n, along with two integer arrays:

  • horizontalCut of length m −1- 1, where horizontalCut[i] represents the cost to perform a horizontal cut along line i.

  • verticalCut of length n −1- 1, where verticalCut[j] represents the cost to perform a vertical cut along line j.

In one operation, you can choose any existing piece of cake and cut it along a horizontal or vertical line:

  • Cutting along horizontal line i incurs a cost of horizontalCut[i].

  • Cutting along vertical line j incurs a cost of verticalCut[j].

Each cut divides a single piece into two smaller pieces. To fully separate multiple pieces along the same line, the cut must be performed individually on each piece, incurring the corresponding cost each time.

Return the minimum total cost required to cut the cake into m ×\times n individual pieces of size 1×11 \times 1.

Constraints:

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

  • horizontalCut.length ==== m −1- 1

  • verticalCut.length ==== n −1- 1

  • 1≤1 \leq horizontalCut[i], verticalCut[i] ≤103\leq 10^3

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost for Cutting Cake I

Try to solve the Minimum Cost for Cutting Cake I problem.

Statement

You are given two integers m and n representing a cake of size m ×\times n, along with two integer arrays:

  • horizontalCut of length m −1- 1, where horizontalCut[i] represents the cost to perform a horizontal cut along line i.

  • verticalCut of length n −1- 1, where verticalCut[j] represents the cost to perform a vertical cut along line j.

In one operation, you can choose any existing piece of cake and cut it along a horizontal or vertical line:

  • Cutting along horizontal line i incurs a cost of horizontalCut[i].

  • Cutting along vertical line j incurs a cost of verticalCut[j].

Each cut divides a single piece into two smaller pieces. To fully separate multiple pieces along the same line, the cut must be performed individually on each piece, incurring the corresponding cost each time.

Return the minimum total cost required to cut the cake into m ×\times n individual pieces of size 1×11 \times 1.

Constraints:

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

  • horizontalCut.length ==== m −1- 1

  • verticalCut.length ==== n −1- 1

  • 1≤1 \leq horizontalCut[i], verticalCut[i] ≤103\leq 10^3