F - Earn to Advance 解説 by en_translator
The first action of “increasing money by \(P_{i,j}\)” can be instead considered “increase money by the maximum \(P_{i,j}\) among the cells passed through so far” without changing the answer.
Therefore, one can assume that he earns money only when needed; this way, once a path is fixed, (one of) the optimal procedure(s) is uniquely determined.
Especially, the only information we need to memorize is “the maximum \(P_{i,j}\) among the cells passed through so far,”
so one can perform DP (Dynamic Programming) as follows: \(\mathrm{DP}[C][P=]\) the maximum\({}^\dagger\) (number of action, money) when being at cell \(C\), and the maximum \(P_{i,j}\) among the cells passed through so far.
\(\dagger\) minimized number of action, ties broken by maximized money
This DP has \(O(N^4)\) states, and the transition costs \(O(1)\) time, so it can be solved in a total of \(O(N^4)\) time.
投稿日時:
最終更新: