Пожалуйста, подпишитесь на официальный канал Codeforces в Telegram по ссылке https://t.me/codeforces_official. ×

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

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

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
  • Проголосовать: не нравится

»
9 лет назад, # |
  Проголосовать: нравится -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.

  • »
    »
    9 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Why do you say that in every step there are 4 strips that can be removed? In fact for completing a column you actually have lots of configurations.

    For example you can have something like this:

    1 2 3 4
    5
    7 8
    9 1 2 3
    

    you can complete the figure like this (assuming that every new strip is valid):

    1 2 3 4
    5 x x x
    7 8 y y
    9 1 2 3
    

    or

    1 2 3 4
    5 x y z
    7 8 y z
    9 1 2 3
    

    and some more. There are obviously more than 4 ways to complete it.

    • »
      »
      »
      9 лет назад, # ^ |
      Rev. 4   Проголосовать: нравится -13 Проголосовать: не нравится

      I meant in each step.
      One step = removing one edge. (One of the 4 edges : top, bottom, right, left)
      In problem statement :
      "He can begin with ploughing a slice from any of the field's edges"
      "Once the nag starts to plough a slice, it won't stop until the slice is completely ploughed."
      "After the ploughing of every successive slice, the yet-unploughed field has a rectangular shape."
      This means that one step is one whole edge; is it not?

      I did not understand your counter example case. Is it not a rectangular region? What do you mean by x,y?

      • »
        »
        »
        »
        9 лет назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        well, think about x, y and z as rectangular regions that you add each step. However, I still believe that this greedy won't work.

        • »
          »
          »
          »
          »
          9 лет назад, # ^ |
            Проголосовать: нравится 0 Проголосовать: не нравится

          Ok, If x, y and z were rectangular regions that you add in your step, my point is that wont be my first step. My first step is always an outer edge of the initial rectangle.

  • »
    »
    9 лет назад, # ^ |
      Проголосовать: нравится +13 Проголосовать: не нравится

    You don't need equality to break this greedy. Did you even try?

    • »
      »
      »
      9 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      I don't understand you. What do you mean by equality? Could you please elaborate more? And could you answer me why ramprakash_k says that there are 4 strips to be removed?

    • »
      »
      »
      9 лет назад, # ^ |
      Rev. 3   Проголосовать: нравится -11 Проголосовать: не нравится

      Equality case arises with my greedy approach and needs to be handled.

      • »
        »
        »
        »
        9 лет назад, # ^ |
          Проголосовать: нравится +6 Проголосовать: не нравится

        Man, your greedy is clearly wrong, don't be so stubborn about your solution if you don't know if that's correct.

        • »
          »
          »
          »
          »
          9 лет назад, # ^ |
            Проголосовать: нравится 0 Проголосовать: не нравится

          any idea for a solution??

          • »
            »
            »
            »
            »
            »
            9 лет назад, # ^ |
              Проголосовать: нравится +1 Проголосовать: не нравится

            Now I'm preparing for my tomorrow's algebra exam and I don't know solution and remember that this was not an easy problem, so for now — no :P.