Skip to content
playdsa
Preferences

Make yourself comfortable.

Saved on this browser. Your device’s reduced-motion preference is always respected.

Theme
Advanced settings

The Coin Combinations

Learn
Play
Prove
Problem context and objectives
Mission briefing

Dungeon strategy engineer · A robot must cross a tiled dungeon

Store enough solved tile states to plan the complete route: The Coin Combinations.

A greedy step can trap the robot; recomputing every route is too expensive.

How you win

  1. 1Recognize when Unbounded knapsack combinations matches the clues
  2. 2Keep this true after every move: after a coin type, dp[amount] counts combinations using only processed coin types
  3. 3Reach the result within O(amount times coin count) time and O(amount) space

Rules and pressure

  • Target cost: O(amount times coin count) time and O(amount) space
  • State rule: after a coin type, dp[amount] counts combinations using only processed coin types
Lesson 1 of 3

Live algorithm trace

Unbounded knapsack combinations

Complete execution
1 of 5
1
2
5
0
amount
1
2

Seed amount zero with one empty combination.

1dp[0] = 1
2for each coin type
3for amount from coin through target
4extend combinations at amount - coin
5dp[amount] += dp[amount - coin]
6return dp[target]
target = 5dp = [1,0,0,0,0,0]
Truth to preserve / Cost target
Truth to preserve

after a coin type, dp[amount] counts combinations using only processed coin types

Cost target

O(amount times coin count) time and O(amount) space

Process coin types outside and amounts inside. This order lets each combination appear once, regardless of the order its coins could be listed.

Your call · What should guide every step of this algorithm?

Help shape PlayDSA

Something confusing, broken, or missing? Leave a quick note without leaving your lesson.

Please leave out passwords, payment details and other private information.

Page included: /

Sign in to save feedback here, or send it with your email app. Your draft stays here while you sign in.

Open email instead