We are playing the Guess Game. The game is as follows:
I pick a number from 1 to n. You have to guess which number I picked.
Every time you guess wrong, I’ll tell you whether the number I picked is higher or lower.
However, when you guess a particular number x, and you guess wrong, you pay $x. You win the game when you guess the number I picked.
Example:
Given a particular n ≥ 1, find out how much money you need to have to guarantee a win.
解法1:
试着去选择每一个数作为猜测的答案,然后分为左边和右边分别考虑。
用一个dp记录子问题的结果,dp数组只需要按照对角线填充就可以了。
C++
Java