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

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

there are N items and a budget of D dollars
each item has a stock S (you can buy at most S of that item) A, B , and value X
the cost for k of that item is (A + (k-1)* B)
what is the maximum value can be attained given this budget ??
1 <= N <=2000
1<= D <= 5000
1<= X,S <= 10^7
0<= B <= A <= D

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

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

What's wrong with the simple Bounded-Knapsack algorithm?

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

    I couldn't find any clear Bounded-Knapsack tutorial
    but in Wikipedia Bounded-Knapsack is as same as this problem but the cost of the second piece of
    any item equal the cost of the first piece
    can you pleas give any good tutorial for it ?

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

      dp[i][j] ->You can buy only items 1,...,i and you have j dollars,what's the maximum number of items you can buy?

      dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - Ai] + 1, dp[i - 1][j - Ai - Bi] + 2, ..., dp[i - 1][j - Ai - x * Bi] + x + 1)

      Except dp[i][j] for all the others ( dp[i][x] ) x%Bi = (j - Ai)%Bi so you can get something like deque to do this things: push_back,pop_front, and return maximum.

      Think how to do this without using some extra structure(like set or map).

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

what he said ^^^

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

"the cost for k of that item is (A + (k-1)* B)" — that is not clear for me

Are costs of following items of that type A, B, B, B, ... or A, A+B, A+2B, ... ?

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +16 Проголосовать: не нравится

The exact same problem is available on HackerRank : https://www.hackerrank.com/contests/indeed-prime-codesprint/challenges/hats and it also contains a good editorial