# Input & Pre-processing: N = int(input()) flavors = [] dic = {i:[] for i inrange(1, N + 1) }
for _ inrange(N): f, d = map(int, input().split()) dic[f].append(d) flavors.append((f, d)) flavors.sort(key=lambda x: x[1], reverse=True)
ans = 0 # Same flavor for f inrange(1, N + 1): iflen(dic[f]) >= 2: dic[f].sort(reverse=True) ans = max(ans, dic[f][0] + dic[f][1] // 2) # Diff flavor for f, d in flavors[1:]: if f != flavors[0][0]: ans = max(ans, flavors[0][1] + d) break print(ans)
import math # Input N = int(input()) checkpoints = [list(map(int, input().split(" "))) for _ inrange(N)] # coordinates of checkpoint i
BOUND = min(N, 30) dp = [[math.inf] * BOUND for _ inrange(N)] dp[0][0] = 0 for i inrange(N): for j inrange(BOUND): next_i = i + 1 + j # 找到下一個點,中間跳過j個點 if next_i >= N: break distance = math.dist(checkpoints[i], checkpoints[next_i]) # 跳過j個點的轉移方程:dp[i+j+1][k] = min(dp[[i+j+1][k], dp[i][k-j] + distance) for k inrange(j, BOUND): # 對k = [j, BOUND) 的範圍進行更新 dp[next_i][k] = min(dp[next_i][k], dp[i][k-j] + distance) ans = dp[N-1][0] # 跳過0個點的最短路徑,penalty = 0 for k inrange(1, BOUND): ans = min(ans, dp[N-1][k] + 2**(k-1)) print(ans)
寫在最後
Cover photo is created by @保科灬有希, thanks for their work!
If the content of the article infringes on your copyright, please contact me through email or leave a comment to let me know, and I will promptly remove the relevant content.