小米笔试第一题,python3,DP
import sys
lines = sys.stdin.readline()
l = list(map(int, lines.strip().split()))
left_num = sum(l)
dp = [[0, ] * len(l) for _ in range(len(l))]
for i in range(len(l)):
if len(l) % 2 == 0:
dp[i][i] = -l[i]
else:
dp[i][i] = l[i]
for s in range(1, len(l)):
for i in range(len(l)-s):
j = i+s
dp[i][j] = max(dp[i][i] - dp[i+1][j], dp[j][j] - dp[i][j-1])
# print(dp)
if len(l) % 2 == 1:
print("Yes") if dp[0][len(l)-1] >= 0 else print("No")
if len(l) % 2 == 0:
print("Yes") if dp[0][len(l)-1] <= 0 else print("Yes")
#笔试题目##Python##小米##题解#
lines = sys.stdin.readline()
l = list(map(int, lines.strip().split()))
left_num = sum(l)
dp = [[0, ] * len(l) for _ in range(len(l))]
for i in range(len(l)):
if len(l) % 2 == 0:
dp[i][i] = -l[i]
else:
dp[i][i] = l[i]
for s in range(1, len(l)):
for i in range(len(l)-s):
j = i+s
dp[i][j] = max(dp[i][i] - dp[i+1][j], dp[j][j] - dp[i][j-1])
# print(dp)
if len(l) % 2 == 1:
print("Yes") if dp[0][len(l)-1] >= 0 else print("No")
if len(l) % 2 == 0:
print("Yes") if dp[0][len(l)-1] <= 0 else print("Yes")