When submitting a solution in C++, please select either C++14 (GCC 6-32) or C++17 (GCC 7-32) as your compiler. ×

ReadDead's blog

By ReadDead, history, 5 years ago, In English

Given K <= 100 types of sticks, each stick i having Li units of length, and Pi as prize of the stick and there is an unlimited amount of sticks from each type. We have to connect multiple sticks together so that total length of chosen sticks is exactly N and total prize is small as possible.

I'm struggling to find any solution within the limits of the time limit — 1s, because of the length N which can reach up to 10^9. Can someone give me any techniques required to solve the problem(i know the solution with O(NK) time complexity-not good for time limit), or report if there aren't any.

Thank you :)

Tags #dp
  • Vote: I like it
  • +8
  • Vote: I do not like it

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by ReadDead (previous revision, new revision, compare).

»
5 years ago, # |
  Vote: I like it +1 Vote: I do not like it

Are there any constraints about the length and price of sticks?

  • »
    »
    5 years ago, # ^ |
    Rev. 3   Vote: I like it 0 Vote: I do not like it

    I have ridden two versions of the problem: - One is where for every i, 2 <= Li <= 1 000; - and for second one we know nothing about the lengths of sticks, but it guaranties that there is stick with length 1 and prize for any stick is 1.