Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
36
Task/Knapsack-problem-0-1/Yabasic/knapsack-problem-0-1.basic
Normal file
36
Task/Knapsack-problem-0-1/Yabasic/knapsack-problem-0-1.basic
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
N = 7 : G = 5 : a = 2^(N+1) ' Author: DANILIN & Editor: Jjuanhdez or Unknow
|
||||
dim L(N), C(N), j(N), q(a), d(a), q$(a)
|
||||
|
||||
for i = a-1 to int((a-1)/2) step -1
|
||||
k = i
|
||||
repeat // cipher 0-1
|
||||
q$(i) = ltrim$(str$(mod(k, 2))) + q$(i)
|
||||
k = int(k / 2)
|
||||
until k = 0
|
||||
q$(i) = mid$(q$(i), 2, len(q$(i)))
|
||||
next i
|
||||
|
||||
print " # Mass Cost"
|
||||
for i = 1 to N
|
||||
L(i) = int(ran(3)) + 1 // mass & cost
|
||||
C(i) = 10 + int(ran(9))
|
||||
print i, chr$(9), L(i), chr$(9), C(i)
|
||||
next i // origin
|
||||
|
||||
print chr$(10) + "Mass Cost Chifer"
|
||||
for h = a-1 to (a-1)/2 step -1
|
||||
for k = 1 to N
|
||||
j(k) = val(mid$(q$(h), k, 1)) // j() = cipher
|
||||
q(h) = q(h) + L(k) * j(k) * C(k) // 0 or 1
|
||||
d(h) = d(h) + L(k) * j(k)
|
||||
next k
|
||||
if d(h) <= G print d(h), chr$(9), q(h), chr$(9), q$(h)
|
||||
next h
|
||||
|
||||
print chr$(10) + "Mass MAX Chifer"
|
||||
maxx = 0 : h = 1
|
||||
for i = 1 to a
|
||||
if d(i) <= G and q(i) > maxx maxx = q(i) : h = i
|
||||
next i
|
||||
print d(h), chr$(9), q(h), chr$(9), q$(h)
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue