[CF] 189A - Cut Ribbon

A simple dynamic programming question.
My Solution
Simply use dynamic programming. use dp[i] to indicate the maximum number of pieces for lenth i. The fromula would be dp[i] = 1 + max({dp[i-a], dp[i-b], dp[i-c]})
Idea:
1 |
|
Official Solution
The problem is to maximize x+y+z subject to ax+by+cz=n. Constraints are low, so simply iterate over two variables (say x and y) and find the third variable (if any) from the second equation. Find the maximum over all feasible solutions.
Or use DP.
Probably bruteforce takes less space, time complexity for DP is O(n / a)
, for bruteforce is the same.
Thoughts
Easy DP question.