On this article, we’ll write C# implementation for Knapsack drawback
utilizing System; utilizing System.Collections.Generic; utilizing System.Linq; utilizing System.Textual content; utilizing System.Diagnostics; namespace KnapsackAlgo { class KnapsackAlgorithm public static int KnapSack(int capability, int[] weight, int[] worth, int itemsCount) int[,] Okay = new int[itemsCount + 1, capacity + 1]; for (int i = 0; i <= itemsCount; ++i) for (int w = 0; w <= capability; ++w) if (i == 0 return Okay[itemsCount, capacity]; static void Important(string[] args) int[] worth = 10, 50, 70 ; int[] weight = 10, 20, 30 ; int capability = 40; int itemsCount = 3; int outcome = KnapSack(capability, weight, worth, itemsCount); Console.WriteLine(outcome); }
Output:
80
Thanks for visiting !!
© 2017, Csharp Star. All rights reserved.