Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
|
|
@ -4,26 +4,26 @@ items := ["map","compass","water","sandwich","glucose","tin","banana","apple","c
|
|||
acc := Array(1..numelems(vals)+1,1..400+1,1,fill=0):
|
||||
len := numelems(weights):
|
||||
for i from 2 to len+1 do #number of items picked + 1
|
||||
for j from 2 to 401 do #weight capacity left + 1
|
||||
if weights[i-1] > j-1 then
|
||||
acc[i,j] := acc[i-1, j]:
|
||||
else
|
||||
acc[i,j] := max(acc[i-1,j], acc[i-1, j-weights[i-1]]+vals[i-1]):
|
||||
end if:
|
||||
end do:
|
||||
for j from 2 to 401 do #weight capacity left + 1
|
||||
if weights[i-1] > j-1 then
|
||||
acc[i,j] := acc[i-1, j]:
|
||||
else
|
||||
acc[i,j] := max(acc[i-1,j], acc[i-1, j-weights[i-1]]+vals[i-1]):
|
||||
end if:
|
||||
end do:
|
||||
end do:
|
||||
printf("Total Value is %d\n", acc[len+1, 401]):
|
||||
count := 0:
|
||||
i := len+1:
|
||||
j := 401:
|
||||
while (i>1 and j>1) do
|
||||
if acc[i,j] <> acc[i-1,j] then
|
||||
printf("Item: %s\n", items[i-1]):
|
||||
count := count+weights[i-1]:
|
||||
j := j-weights[i-1]:
|
||||
i := i-1:
|
||||
else
|
||||
i := i-1:
|
||||
end if:
|
||||
if acc[i,j] <> acc[i-1,j] then
|
||||
printf("Item: %s\n", items[i-1]):
|
||||
count := count+weights[i-1]:
|
||||
j := j-weights[i-1]:
|
||||
i := i-1:
|
||||
else
|
||||
i := i-1:
|
||||
end if:
|
||||
end do:
|
||||
printf("Total Weight is %d\n", count):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue