小马智行第2ac, 第3动规30%,思路估计错了。贴上第二题
""" 青蛙跳:只能跳下一个或者跳与自己最近的相同颜色的台阶,c是台阶颜色 """ n = int(input()) c = [int(i) for i in input().split()] def getMinSteps(n, c): dic_c = {} if n<=2: return n-1 dp = [n]*n dp[0],dp[1] = 0, 1 dic_c[c[0]] = 0 dic_c[c[1]] = 1 for i in range(2, n): if c[i] in dic_c: dp[i] = min(dp[ dic_c[ c[i] ] ]+1, dp[i-1]+1) else: dp[i] = dp[i-1]+1 dic_c[ c[i] ] = i return dp[-1] print(getMinSteps(n, c))