程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Blue Bridge Cup [11th finals] blue jump Python 30 points

編輯:Python

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


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved