Thinking Process
Code
Greedy (Wrong Answer)
Time Complexity: O((R+G+B)log(R+G+B)), Space Complexity: O(R+G+B)
一開始寫的 Greedy 解法(Wrong Answer!),考慮以下的 case:
R = 3, 3, G = 4, B = 5,則 Greedy 會給出 20,但是答案應該是 27。所以說這題不行用 Greedy(只有兩個顏色的話當然可以),要用 DP。
DP
Time Complexity: O(RGB+RlogR+GlogG+BlogB), Space Complexity: O(RGB)
Source