Блог пользователя WALL-E__

Автор WALL-E__, история, 5 лет назад, По-английски

i am having problem in solving this problem using 0/1 knapsack problem. http://codeforces.com/contest/19/problem/B

  • Проголосовать: нравится
  • +13
  • Проголосовать: не нравится

»
5 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

You need to keep two states:

I: Current item.

R: Number of items remaining.

The transition is, take the item I paying ci and go to the item I + 1 with R - 1 - ti remaining items, or dont take the item I and go to the item I + 1 with R remaining items.

»
5 лет назад, # |
  Проголосовать: нравится +15 Проголосовать: не нравится

There's a simple solution that runs in O(2N). Just try all combinations and keep the best.

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

    But 1 ≤ N ≤ 2000, do you have some super computer ?

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

      Well, not me, but the studios where I usually work make 3D movies too, so they have a farm of around 45 powerful computers running at the same time.

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

        Wow, in how many seconds them run 22000 operations ?, can you give me one powerful computer ?

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

          Well, you can do the math. One powerful computer can do 1000 million operations per second, which is around 230, so it can do 60 * 230 in a minute. That's around 236 in a minute and 242 in one hour, so it would take something like 21958 hours to run the solution. One year has 213 hours approximately, so it will take 21945 years. Is it good enough?

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

            Complexity if exponential, but you can get it to run under 1000ms (in java) using the sleep.thread() trick. This should be common knowlegde.

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

              Indeed, or you can use #pragma lightspeed in C++55, which will be released in 37 years. But since it uses black hole quantum physics to compile and run, it doesn't matter, you can use it today by calling that pragma.

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

                So it turns out C++ really is better at everything. I think using a bitset will reach O(1/n) (watch out for n = 0) complexity, but seems that its too difficult for a simple problem as this

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

    Maybe with more pruning than luck code. I use a branch and bounds algorithm with the upper bound $$$U_2$$$.

»
5 лет назад, # |
Rev. 2   Проголосовать: нравится -6 Проголосовать: не нравится

Another way is [itemupto][time] with observation time > 2000 dont matter. do we store dp[item][time] = minimum cost.

Note that for each item we can "add" 1 second to it because it takes care of itself.

And we us the dp table to solve problem.

EDIT: Wow it seems I've greatly infected the integrity of CF by giving out correct solutions! The horror!