Old Top Coder riddle: Making a number by inserting +

后端 未结 6 1678
借酒劲吻你
借酒劲吻你 2021-02-06 05:41

I am thinking about this topcoder problem.

Given a string of digits, find the minimum number of additions required for the string to equal some target n

6条回答
  •  离开以前
    2021-02-06 06:08

    It's certainly not optimal. If, for example, you are given the string "1234567890" and the target is a three-digit number, you know that you have to split the string into at least four parts, so you need not check 0, 1, or 2 inserts. Also, the target limits the range of admissible insertion positions. Both points have small impact for short strings, but can make a huge difference for longer ones. However, I suspect there's a vastly better method, smells a bit of DP.

提交回复
热议问题