Anonymous user
Knapsack problem/Bounded: Difference between revisions
→{{header|C#}}
Line 559:
knapSack(40);
var sw = System.Diagnostics.Stopwatch.StartNew();
Console.Write(knapSack(400) + "\n" + sw.Elapsed); //
Console.Read();
}
Line 565:
static string knapSack(uint w1)
{
uint n = (uint)w.Length; var K = new uint[n + 1, w1 + 1];
for (uint
for (vi = v[i], wi =
x = K[i
if (wi <= w0) x = max(
K[i + 1, w0] = x;
for (uint v1 = K[n, w1]; v1 > 0; n--)
if (v1 != K[n - 1, w1])
{
}
return str;
}
Line 622 ⟶ 625:
}
}</lang>
=={{header|Clojure}}==
We convert the problem to a Knapsack-0/1 problem by replacing (n-max item) vith n-max identical occurences of 1 item.
|