#### Category : knapsack-problem

When I am changing the order of isPossible function then it’s giving wrong answer otherwise present code gives correct answer. I wanted to know why this is happening. Here is the problem statement: https://leetcode.com/problems/partition-equal-subset-sum/submissions/ Here is my accepted solution class Solution { unordered_map<int, bool> um; public: bool isPossible(vector<int>&nums, int currentIndex, int sum){ if(sum == 0){ ..

Hello i need to adapt some problems with dynamic programming to work with more than the conventional number of objects that they usually works like adapt the knapsack problem to work with N sacks instead of 1 and Longest Common Subsequence to work with N strings instead the usual 2. I found that one way ..

Codeforces Round 683 Knapsack Problem I tried this knapsack problem by this method but i got wrong answer . In my code below i calculated my till it was the least less than W . In one solution the sum was taken till the least more than W/2 and it was correct. So what is ..

Problem: I have a list number of candies I would receive for n stalls. I could only visit w stalls. The stall number which I visit would be saved in x[w] (sorted in ascending order). I could receive bonus candies A*max(0, B-(x[i+1] – x[i])). I have to plan out which stalls I have to visit ..

I’m learning algorithms for solving the 0/1 knapsack problem, and I found this nice solution with brute-force. How about its performance if we try to contrast it with a recursive way? About this solution(just my opinion): we use a bit to describe the object is included or not(0 means excluded, 1 means included), so we ..

I have written a brute force algorithm in R and it does work fine. I want to implement using Rcpp so that my code runs faster however I can’t get it to work. for example for a simple example w = [4 2 3] , v = [10 7 4] with maximum weight W=5 it ..

#include <fstream> #include <iostream> #include <vector> using namespace std; int max(int a, int b) { return (a > b) ? a : b; } int knapsack(int W, vector<int> wt, vector<int> val, int n, vector<bool>& include) { unsigned int i; if (n == 0 || W == 0) { return 0; } if (wt.size() > W) ..