1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | import sys def recur(s, e): if s == e: return 0 if dp[s][e]: return dp[s][e] if s + 1 == e: return arr[s][0] * arr[s][1] * arr[e][1] for i in range(s, e): temp = recur(s, i) + recur(i + 1, e) + arr[s][0] * arr[i][1] * arr[e][1] if not dp[s][e] or temp < dp[s][e]: dp[s][e] = temp return dp[s][e] n = int(sys.stdin.readline().rstrip()) MIN = 1e9 dp = [[0] * n for _ in range(n)] arr = [] for i in range(n): a, b = map(int, sys.stdin.readline().rstrip().split()) arr.append((a, b)) print(recur(0, n – 1)) | cs |