fix: changed problem time_limit back to 1s, and updated python solution.
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -1,7 +1,7 @@
|
|||||||
\documentclass{maratona}
|
\documentclass{maratona}
|
||||||
|
|
||||||
\begin{document}
|
\begin{document}
|
||||||
\begin{ProblemaAutor}{}{Estouro}{1.5}{256}{Arthur Andrade D'Olival}
|
\begin{ProblemaAutor}{}{Estouro}{1}{256}{Arthur Andrade D'Olival}
|
||||||
|
|
||||||
No laboratório de experimentos caóticos da \textbf{Fábrica de Balões Numéricos}, um cientista excêntrico te entrega uma fileira de balões, cada um pintado com um número inteiro positivo.
|
No laboratório de experimentos caóticos da \textbf{Fábrica de Balões Numéricos}, um cientista excêntrico te entrega uma fileira de balões, cada um pintado com um número inteiro positivo.
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
"problem": {
|
"problem": {
|
||||||
"title": "Estouro",
|
"title": "Estouro",
|
||||||
"event": "",
|
"event": "",
|
||||||
"time_limit": 1.5,
|
"time_limit": 1.0,
|
||||||
"memory_limit_mb": 256,
|
"memory_limit_mb": 256,
|
||||||
"input_file": "stdin",
|
"input_file": "stdin",
|
||||||
"output_file": "stdout",
|
"output_file": "stdout",
|
||||||
|
|||||||
@@ -1,31 +1,14 @@
|
|||||||
n = int(input())
|
n = int(input())
|
||||||
arr = list(map(int, input().split()))
|
nums = list(map(int, input().split()))
|
||||||
|
|
||||||
nums = [1] + arr + [1]
|
nums = [1] + nums + [1]
|
||||||
m = n + 2
|
|
||||||
|
|
||||||
dp = [[0] * m for _ in range(m)]
|
dp = [[0] * len(nums) for _ in range(len(nums))]
|
||||||
|
|
||||||
for length in range(2, m):
|
for length in range(3, len(nums) + 1):
|
||||||
for left in range(m - length):
|
for i in range(len(nums) - length + 1):
|
||||||
right = left + length
|
j = i + length - 1
|
||||||
|
for k in range(i + 1, j):
|
||||||
|
dp[i][j] = max(dp[i][j], dp[i][k] + dp[k][j] + nums[i] * nums[k] * nums[j])
|
||||||
|
|
||||||
best = 0
|
print(dp[0][len(nums) - 1])
|
||||||
left_val = nums[left]
|
|
||||||
right_val = nums[right]
|
|
||||||
|
|
||||||
row_left = dp[left]
|
|
||||||
|
|
||||||
for k in range(left + 1, right):
|
|
||||||
val = (
|
|
||||||
row_left[k]
|
|
||||||
+ dp[k][right]
|
|
||||||
+ left_val * nums[k] * right_val
|
|
||||||
)
|
|
||||||
|
|
||||||
if val > best:
|
|
||||||
best = val
|
|
||||||
|
|
||||||
row_left[right] = best
|
|
||||||
|
|
||||||
print(dp[0][m - 1])
|
|
||||||
Reference in New Issue
Block a user