>

Educational DP Contest

Educational DP Contest A - Frog 1 你有 N 個平台。平台編號為 1, 2, …, N。對於每個 i (1 ≤ i ≤ N),平台 i 的高度是 h_i。 最初,一隻青蛙在平台 1 上。 青蛙重複以下動作,試圖到達平台 N: 當青蛙在平台 i 上時,它跳到平台 i + 1 或 i + 2。 當跳到平台 j 時,它支付成本 |h_i - h_j|。 求青蛙到達平台 N 所需支付的最小總成本。 n = int(input()) h = list(map(int, input().split())) dp = [0] * n dp[1] = abs(h[1] - h[0]) for i in range(2, n): dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2])) print(dp[-1]) B - Frog 2 有 N 個立足點。立足點的編號是 1, 2, …, N。對每個 i (1 ≤ i ≤ N),立足點 i 的高度是 h_i。 ...

Math Algo

Algo and Math 001 - Print 5+N print(int(input()) + 5) 002 - Sum of 3 Integers print(sum(map(int, input().split()))) 003 - Sum of N Integers input() print(sum(map(int, input().split()))) 004 - Product of 3 Integers import functools import operator print(functools.reduce(operator.mul, map(int, input().split()))) 005 - Modulo 100 input() print(sum(map(int, input().split())) % 100) 006 - Print 2N+3 print(int(input()) * 2 + 3) 007 - Number of Multiples 1 在不超過 N 的正整數中,有多少個數是 X 的倍數,或者 Y 的倍數? import math n, x, y = map(int, input().split()) print(n // x + n // y - n // math.lcm(x, y)) 008 - Brute Force 1 你有兩張卡片,分別是紅色和藍色,你需要在每張卡片上寫下 1 到 N 之間的整數。有多少種寫法可以讓卡片上數字的總和不超過 S? ...