f(p, i, m)
with memoization.i == n
, return 0
(base case).dp[p][i][m] != -1
, return dp[p][i][m]
(memoized result).s
and res
for the current move.x
from 1
to min(2m, n - i)
.
s
with the sum of stones in the x
piles.p == 0
, update res
with s + f(1, i + x, max(m, x))
if it's larger.p == 1
, update res
with f(0, i + x, max(m, x))
if it's smaller.res
in dp[p][i][m]
.res
.dp
with -1
and call f(0, 0, 1)
.