Блог пользователя dcordb

Автор dcordb, 12 лет назад, По-английски

Could you help me with this problem from the 13th POI:
http://main.edu.pl/en/user.phtml?op=showtask&task=ork&con=OI13

It seems some kind of DP, but I'm not able to get it. So far I have an idea: to keep the state of the columns and try to filling them adding a valid rectangle, but this is too slow. Could you help me? Thanks beforehand.

Теги dp, poi
  • Проголосовать: нравится
  • +3
  • Проголосовать: не нравится

»
12 лет назад, скрыть # |
 
Проголосовать: нравится -24 Проголосовать: не нравится

Dynamically you can get the sum of elements in any strip needed (store cumulative column and row sums).

At each step, you have 4 possible strips that you can remove. Remove that strip whose sum is the maximum among those which have sum <= k. If more than one have the same highest sum, remove the longer strip. (This can be done in constant time.)

Number of steps cannot exceed m+n. So, this algo is O(m+n).

However, I am not completely sure this is correct. I haven't checked the equality case fully.