using System.Collections.Generic;
public static void Main()
int[] wt = new int[] { 53, 88, 78, 72, 30, 46 };
int[] val = new int[] { 45, 98, 3, 76, 9, 48 };
int[, ] dp = new int[n + 1, W + 1];
Console.WriteLine(knapSack(W, wt, val, n, dp));
Console.WriteLine(getSelectedItems(n, W, val, dp));
Console.WriteLine("Hello World");
static String getSelectedItems(int n, int W, int[] val, int[, ] dp)
List<int> selectedItems = new List<int>();
int cost = dp[n, tempWeight];
for (int i = n; i > 0; i--)
int j = containsCost(cost, i - 1, W, dp);
cost = cost - val[i - 1];
return selectedItems.Count > 0 ? String.Join(",", selectedItems) : "-";
static int containsCost(int n, int i, int W, int[, ] dp)
for (int j = 0; j <= W; j++)
static int max(int a, int b)
static int knapSack(int W, int[] wt,
int[] val, int n, int[, ] K)
+ K[i - 1, w - wt[i - 1]],