DP L
L - Deque
Competitive Game Read-Out Issues
DP with the board as the domain of definition
The board can be represented by a range
There is no need to distinguish between the first and the second hand.
Maximize "my score - opponent's score" for both the first and second moves.
Unmemorized naive recursion.
All sample codes succeed.
code:python
def solve(N, XS):
def first(L, R):
# debug(": L, R", L, R)
if L == R:
return XSL
return max(
XSL - first(L + 1, R),
XSR - first(L, R - 1)
)
return first(0, N - 1)
Compile in Cython because it is TLE as it is.
I put in an array that has a value that cannot be taken to make sure it has not been calculated, but since it can be both positive and negative, I also created an array that has a value that has been calculated or not.
You could have left the value large enough.
I used int because it was an error to use bool.
code:cython
cdef long3000 * 3000 memo
cdef int3000 * 3000 done
cdef first(L, R):
if L == R:
return XSL
pos = L * N + R
if donepos + N:
right = memopos + N
else:
right = first(L + 1, R)
if donepos - 1:
left = memopos - 1
else:
left = first(L, R - 1)
ret = XSL - right
x = XSR - left
if x > ret:
ret = x
memopos = ret
donepos = True
return ret
cdef solve():
for i in range(N * N):
memoi = 0
donei = False
return first(0, N - 1)
def main():
global N, XS
# parse input
N = int(input())
XS = list(map(int, input().split()))
print(solve())
https://atcoder.jp/contests/dp/submissions/15060096
---
This page is auto-translated from /nishio/DP L using DeepL. If you looks something interesting but the auto-translated English is not good enough to understand it, feel free to let me know at @nishio_en. I'm very happy to spread my thought to non-Japanese readers.