Base case: (take the only pile). Fill by increasing length. For each interval, try taking left or right end. The "difference" formulation elegantly handles the zero-sum game. Both players play optimally. Time: , Space: . Can reduce space to since each length only depends on previous length. Fill the table by increasing interval length. Each cell depends on two smaller intervals. This keeps dependencies valid.
Time complexity: .
Space complexity: .