The score is not high , Or have the cheek to write
limit, cond, length = map(int, input().split())
mod = 20201114
dp = [[0, 0] for _ in range(length + 1)]
dp[0] = [1, 0]
# Represent the : There is no limit to jumping , Jumping is limited
Read input , Then use a one-dimensional list dp To record the status ,dp[0] Represents the state at the starting point , Among them [1, 0] Represent the :“ There is no limit to jumping ” Number of alternatives 、“ Jumping is limited ” Number of alternatives
State transition is simple , Such as :
The distance between the current point and the starting point is dist,dp[dist][0] It's next “ There is no limit to jumping ” Number of alternatives ,dp[dist][1] It's next “ Jumping is limited ” Number of alternatives . Enumerate jump distances pace, If pace >= cond, Then the place of arrival “ Jumping is limited ” Number of alternatives add dp[dist][0]; If pace < cond, Then the place of arrival “ There is no limit to jumping ” Number of alternatives add dp[dist][0] and dp[dist][1]
for dist in range(length):
state_1, state_2 = dp[dist]
dp[dist] = [0, 0]
for pace in range(1, cond):
# pace < cond, There is no limit to the next jump
next_ = dist + pace
if next_ <= length:
# The end of the jump is within the range of the stage
dp[next_][0] += state_1 + state_2
else:
break
for pace in range(cond, limit + 1):
# pace >= cond, The next jump is limited
next_ = dist + pace
if next_ <= length:
# The end of the jump is within the range of the stage
dp[next_][1] += state_1
else:
break
Simple dp Ideas , Pathetic 30 branch , Any problems? ? No problem