Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost to Merge Stones

med
30 min
Try to solve the Minimum Cost to Merge Stones problem.

Statement

You are given an integer array stones where stones[i] represents the number of stones in the iextthi^{ ext{th}} pile, arranged in a row. You are also given an integer k.

In each operation, you can choose exactly k consecutive piles and merge them into a single pile. The cost of this operation is the sum of the stones in those k piles.

Return the minimum cost to merge all piles into one single pile. If it is impossible to merge all piles into one pile, return −1-1.

Constraints:

  • n ==== stones.length

  • 1≤1 \leq n ≤30\leq 30

  • 1≤1 \leq stones[i] ≤100\leq 100

  • 2≤2 \leq k ≤30\leq 30

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost to Merge Stones

med
30 min
Try to solve the Minimum Cost to Merge Stones problem.

Statement

You are given an integer array stones where stones[i] represents the number of stones in the iextthi^{ ext{th}} pile, arranged in a row. You are also given an integer k.

In each operation, you can choose exactly k consecutive piles and merge them into a single pile. The cost of this operation is the sum of the stones in those k piles.

Return the minimum cost to merge all piles into one single pile. If it is impossible to merge all piles into one pile, return −1-1.

Constraints:

  • n ==== stones.length

  • 1≤1 \leq n ≤30\leq 30

  • 1≤1 \leq stones[i] ≤100\leq 100

  • 2≤2 \leq k ≤30\leq 30