Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

chocolate

Name: ecrofirT 2009-08-21 9:32

A man has to buy some chocolate boxes
there are different types of boxes:
weight (kg)/// income ($) that the man gets for each box sold
1               10
2               26
3               43
4               52
5               53
6               56
7               71
8               87
9               95
10             100

Due to legal restrictiohns he can only buy 20 boxes and no more than 100Kg total
Also, he wants to choose 2 sizes because it's easier to commercialize.

so I need to write a program in qb/c/java solving this problem

can you help me? just gimme some ideas or pseaudocode please

I think it has something to do with arrays [weight,income] for each type but I'm lost

Name: Anonymous 2013-05-18 7:06

Snapback problem
https://en.wikipedia.org/wiki/Knapsack_problem

Pseudocode is there to, but you will need to do a fair amount of extra work.


// Input:
// Values (stored in array v)
// Weights (stored in array w)
// Number of distinct items (n)
// Knapsack capacity (W)
for w from 0 to W do
  m[0, w] := 0
end for
for i from 1 to n do
  for j from 0 to W do
    if j >= w[i] then
      m[i, j] := max(m[i-1, j], m[i-1, j-w[i]] + v[i])
    else
      m[i, j] := m[i-1, j]
    end if
  end for
end for



If it were C You probably need to create your own function max() i.e.
int max(int a,int b)        {
    if(a>b)
        return a;
    else
        return b;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List