Category: knapsack

Maximum sum of values of N items in 0-1 Knapsack by reducing weight of at most K items in half

import java.io.*;import java.util.*;  class GFG {          static int maximum(int value[],                       int weight[], int weight1,                       int flag, int K, int index)    {                  if (index >= value.length) {              return 0;        }                          if (flag == K) {                          int skip = maximum(value,                               weight, weight1,                               flag, K, index + 1);              int full = 0;                                                              if (weight[index]

Continue Reading

Sum of length of two smallest subsets possible from a given array with sum at least K

import java.io.*; import java.lang.*; import java.util.*; class GFG{ static int MAX = (int)(1e9); static int MinimumLength(int A[], int N, int K) {                Arrays.sort(A);                int suffix[] = new int[N + 1];          for(int i = N – 1; i >= 0; i–)         suffix[i] = suffix[i + 1] + A[i];          int dp[][] […]

Continue Reading