ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1396. Maximum. Version 2

A solution without any pattern guessing
Posted by Yury_Semenov 17 Oct 2019 17:14
Suppose we want to calculate max({A * a[i] + B * a[i + 1], A * a[i + 1] + B * a[i]}) for i = 0..n-1 (in this problem A = 0, B = 1). Then answer(A, B, n) = max(answer(max(A, B), A + B, n/2), A * a[n - 1] + B * a[n], B * a[n - 1] + A * a[n]), so it can be solved recursively.
Re: A solution without any pattern guessing
Posted by yyll 5 Feb 2022 16:40
That's very clever!
How did you come up with this idea?
Re: A solution without any pattern guessing
Posted by Yury_Semenov 13 Feb 2022 14:24
It's been 2.5 years, so I don't remember clearly, but as far as I remember, I tried expanding formulas to find a simple formula for max. I didn't find such a formula, but I noted that the problem can be parametrized and expanded formulas fit that parametrization well.