Editorial for APIO '10 P1 - Commando


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Solution 1

O(n3): Using dynamic programming, let f(n) indicate the maximum battle effectiveness after adjustment. We have transfer equations below:

f(n)=max0i<n{f(i)+g(j=i+1nXj)},g(x)=Ax2+Bx+C

Such a solution should score around 20%.

Solution 2

O(n2): Use pre-calculated partial sum to accelerate the solution above. Let Si=i=1nXi, we have f(n)=max0i<n{f(i)+g(SnSi)}.

Such a solution should score around 50%.

Solution 3

O(n): Consider two decisions i<j, we choose i instead of j if and only if:

f(i)+g(SnSi)>f(j)+g(SnSj)g(SnSi)g(SnSj)>f(j)f(i)A((SnSi)2(SnSj)2)+B((SnSi)(SnSj))>f(j)f(i)A(2SnSiSj)(SjSi)+B(SjSi)>f(j)f(i)A(2SnSiSj)+B>f(j)f(i)SjSi2Sn<1A(f(j)f(i)SjSiB)+Si+Sj

Thus, we can use a queue holding all necessary decisions. Each decision in the queue is the best decision during a specific range of Sn. When a decision is to be made, we simply begin searching at one end of the queue, and find the first decision where Sn is in its range. After that, we put decision N at the other end of the queue as a new decision, updating the range of decisions before it using the inequality above.

Such a solution should score 100%.


Comments

There are no comments at the moment.