Distinct square-sum portfolios
Dynamic Programming
How many ways can 500 be written as a sum of exactly five DISTINCT positive perfect squares? Different orders of the same five squares count once.
Solve using mathematics, algorithms, or your own code offline. Submit only the final integer here—no program, expression, graph, or written proof.
Check your answer without signing in. Sign in to save your progress.
How to approach this problem
Generate positive squares below the target. Apply subset-sum DP with a selection count, iterating downward so no square is used twice.
Worked example with different values
For target 13 with two distinct positive squares, 4+9 is the only combination. 9+4 is not a separate one.
Apply the same reasoning to the challenge. This example is a separate practice problem.
Learn the technique: Dynamic programming and grid paths