Problem Solving: N-Slimes @ Atcoder
🔥 Visit our website for online classes and camps ➡️ algoritmiacademy.com In this video, Ali solves the "N-Slimes" problem from AtCoder, a classic example of Interval DP (Range DP). The problem asks us to combine N slimes into a single slime with minimum cost. In each step, you can merge two adjacent slimes, and the cost is the sum of their sizes. This structure is identical to the classic "Matrix Chain Multiplication" or "Optimal Binary Search Tree" problems. We break down why a simple greedy approach fails and how to build the solution using Dynamic Programming. The video explains the state definition `DP[L][R]` (minimum cost to merge slimes from index L to R), the transition formula, and how to iterate through length, start index, and split point `K`. What we cover: - Understanding the problem: Merging adjacent elements with cost. - Why Greedy Fails: Counter-examples to simple merging strategies. - Defining Range DP: `DP[L][R] = min(DP[L][K] + DP[K+1][R]) + sum(L...R)`. - Efficiently calculating range sums using a Prefix Sum array (or precomputed 2D array). - Order of computation: Iterating by length (from 2 to N) to build up the answer. - Live implementation in C++. Useful Links =========================== Problem/Submission Link: https://atcoder.jp/contests/dp/tasks/dp_n =========================== Connect with us! =========================== Facebook ➡️︎ www.facebook.com/people/Algoritmi-Academy/61554522885080 LinkedIn ➡️︎ www.linkedin.com/company/algoritmiacademy Telegram ➡️︎ t.me/Algoritmi_Acad X ➡️︎ x.com/algoritmi_acad =========================== ⏰ Timecodes ⏰ =========================== 0:00 - Introduction 0:39 - Problem statement 1:11 - Examples 4:50 - Hints 5:22 - Solution 20:22 - Code =========================== ♫ Music & Sound Effects ♪ =========================== Music by https://www.bensound.com/free-music-for-videos License code: GHGS5VVSDWLXHHUB Music: Bensound License code: LXSZUDWXCD8IH0NT =========================== Images & Vectors =========================== Free Stock Footage by Vecteezy.com ===========================
Download
1 formatsVideo Formats
Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.