Skip to the workspace
Pebellslearn by building
Greedy, Backtracking & Dynamic Programming  ›  Capstone Project

Capstone — Festival Planner

50 minRecognise which technique a problem needs, and compose them

dsa / Capstone — Festival Planner

Explore each scene at your own pace.

01 · Booking the main stage by fans, not count

Booking the main stage by fans, not count

Capstone — Festival Planner

Definition
Choosing an algorithm design technique means recognising the shape of a problem: greedy for picking the most items using a safe local rule, dynamic programming for the best total when choices interact, and backtracking for listing every valid answer.
In plain words
It is learning to read what a question is really asking before you start coding. Most that fit usually means greedy, best total under a budget usually means dynamic programming, and every possibility means backtracking.

In short: this capstone tests recognising which technique a problem is asking for, then wiring the pieces together so each one's output feeds the next. "Most things that fit, with a swap argument" is greedy. "Best total, where choices interact through a budget or overlaps" is dynamic programming. "Every answer, not just the best one" is backtracking. The same planner uses all three, because its three questions are three different shapes wearing the same costume — acts and a festival night.

Three boxes in a row — Main stage (most fans, dynamic programming), Side stage (most acts, greedy), Encore (every exact mix, backtracking) — each feeding the next

Booking the main stage by fans, not count

Tunebox Festival is one night with a main stage, a side stage and a hard curfew. Every act applies with [name, start, end, fans]; the house DJ's crate holds [title, minutes] tracks. The main stage wants the most fans, and earliest-finish greedy — which books the most acts — says nothing about weight:

python

The mistake: that books three acts for 300 + 400 + 500 = 1200 fans, but Kade and Zed alone draw 1300. The exchange argument that proved earliest-finish swaps one act for another — it keeps the count the same, not the fans, so it says nothing about weights. Maximising weight means weighing every act against everything it excludes, which is a DP.

Sort by end time. Let best[i] be the most fans from the first i acts. Act i either sits out (best[i-1]) or plays (fans + best[p], where p is how many acts end by the time act i starts — exactly the acts compatible with it). Because end times are sorted, p is a binary search:

What does this print?
from bisect import bisect_right

ends = [60, 120, 150]
print(bisect_right(ends, 120))
What does this print?
best = [0, 300, 800, 0]
p = 1                                  # only Nova ends by 60, when Luma starts
best[3] = max(best[2], 400 + best[p])  # sit out, or play Luma's 400 after the best of the first p
print(best[3])
step through it
1from bisect import bisect_right
2order = [["Nova", 0, 60, 300], ["Kade", 30, 120, 800], ["Luma", 60, 150, 400]]
3ends = [a[2] for a in order]
4best = [0, 0, 0, 0]
5for i in range(1, 4):
6 name, start, end, fans = order[i - 1]
7 p = bisect_right(ends, start)
8 best[i] = max(best[i - 1], fans + best[p])
9print(best)

Here is the full table for all five acts, then the walk back that reads the lineup out of it. Pointer p marks the last act that ends before the current one starts:

watch it move · array

Each best[i] weighs one act against everything it overlaps, which no single greedy rule can do.

best[0] = 0, because with no acts nobody comes. 6 cells. At index 0.

1 / 9
Scene 1 of 6
Project context and further resources
You're building a piece ofTunebox — festival planner
This piece — plan_festival(): Plans a festival lineup using every technique in the section.
Scenario Tunebox Festival has one night, two stages and a curfew. The planner fills the main stage for the biggest crowd, gives the side stage to as many of the remaining acts as fit, and lists every encore mix that runs exactly to curfew.
plan_festival.py
Call the function you wrote — just like your app's frontend would. Edit the inputs and hit Call.
plan_festival(acts, crate, curfew) → dictThe night's plan: main stage, fans, side stage, encore length and every encore mix.
try:
returned
Press Run to execute your code.
Press Check to run the tests for this lesson.
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.