AC100,唯一一道ac的,尴尬 import sys def InputFunc(): n = int(input()) A = [] for i in range(n): tmp = list(map(int, input().strip().split())) A.append(tmp) return n, A def main(): n, A = InputFunc() if n == 0: print(0) return 0 max_value = sys.maxsize dp = [[max_value]*2 for _ in range(n)] for i in range(n): if i == 0: dp[i][1] = A[i][1] dp[i][0] = A[i][0]+A[i][2] else: dp[i][0] = min(dp[i-1][0]+A[i][0], dp[i-1][1] + A[i][0] + A[i][2]) dp[i][1] = min(dp[i-1][1]+A[i][1], dp[i-1][0] + A[i][1] + A[i][2]) print (min(dp[n-1][0], dp[n-1][1])) if __name__ == "__main__": main()
点赞 2

相关推荐

整顿职场的柯基很威猛:这种不可怕,最可怕的是夹在一帮名校里的二本选手,人家才是最稳的。
点赞 评论 收藏
分享
牛客网
牛客企业服务