Sum of cubes Please,help.
№ | Пользователь | Рейтинг |
---|---|---|
1 | ecnerwala | 3648 |
2 | Benq | 3580 |
3 | orzdevinwang | 3570 |
4 | cnnfls_csy | 3569 |
5 | Geothermal | 3568 |
6 | tourist | 3565 |
7 | maroonrk | 3530 |
8 | Radewoosh | 3520 |
9 | Um_nik | 3481 |
10 | jiangly | 3467 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | maomao90 | 174 |
2 | awoo | 164 |
2 | adamant | 164 |
4 | TheScrasse | 159 |
4 | nor | 159 |
6 | maroonrk | 156 |
7 | -is-this-fft- | 150 |
8 | SecondThread | 147 |
9 | orz | 146 |
10 | pajenegod | 145 |
Sum of cubes Please,help.
Название |
---|
isn't it just dp? suppose dp[i] denotes the minimum number such that the sum of cubes of its digits is i. Then, dp[n]=min(add a digit 9 to left of dp[n-729], add a digit 8 to left of dp[n-512],...,add digit 1 to left of dp[n-1]). This, of course, requires some edge cases. eg. dp[1]=1(base case 1). dp[2]=min(add 1 to left of dp[1])=11. It needs 9*n operations so it is O(n).
Code?
Why do you need a code? I believe that the logic is good enough. I think the code to this would be short and easy. You should give it a try yourself. Or maybe you can ask if you are having a problem somewhere in your own code. Asking for help is one thing and just relying on others is another thing. Please try to understand. I am not discouraging you from asking though.