I am trying to write a brute force solution to the 0-1 knapsack problem that also stores the correct weight value pairs along with returning the correct value. My code so far returns the correct value but I am not sure how I can store the correct weight,value pairs along the way. int knapsackR(int weight, ..

#### Category : algorithm

I am trying to solve a problem: There is a survey that consists of n questions where each question’s answer is either 0 (no) or 1 (yes). The answers of the students are represented by a 2D integer array students where students[i] is an integer array that contains the answers of the ith student (0-indexed) ..

I’ve compiled the same code (MozJpeg project https://github.com/mozilla/mozjpeg ) without problems in Windows but I didn’t manage to do it in Linux since it requires "algorithm" header. I’ve been searching about that header and it seems to be available in other systems not only in Windows but my compiler doesn’t find it. Maybe it could ..

Why the map in my code is storing only two elements instead of three? vector<int> v1 = { 140,229,319 }; vector<int> v2 = { 82,216,326 }; map<int, int> mp; for (int i = 0; i < v1.size(); i++) { if (v1[i] > v2[i]) { mp.insert({ 1,v1[i] – v2[i] }); } else if (v2[i] > v1[i]) ..

In C++20, there exists std::ranges::count(), but no std::ranges::accumulate(). Just an oversight by the C++ committee? Source: Windows Que..

Challenge Date: 24/7/21 Looking for an Approach Source: Windows Que..

When you left-click somewhere on the page, all the elements that are "below" the mouse pointer have their onclick callback invoked (if it is set obviously). I imagine that any click has its x,y coordinates as well as each DOM element has some x1,y1,x2,y2 or something like that. There is some algorithm that finds all ..

You are given a read only array of n integers from 1 to n. Each integer appears exactly once except A which appears twice and B which is missing. Return A and B. Here is the solution tried : vector<int> Solution::repeatedNumber(const vector<int> &A) { int n=A.size(); vector<int> res(2); unordered_map<int, int> m; for(int i=0;i<n;i++){ m[A[i]]++; if(m[A[i]]==2) ..

I’m making a program that’s supposed to be able to find pieces of wood in a dataset to cover a surface. For now I’m focusing on parallelepipedic shapes to simplify the problem (eventually I’d like it to be able to handle any shape). The user should be able to approximate (almost) any 2D or 3D ..

I have a directed graph. Initially, all nodes are assumed to be unvisited and flag is -1 in vector<int>flag. Now we start from a source node & push into stack<int>s and make flag[source]=0 . Now I do DFS traversal & push nodes if(flag[node]==-1)& make flag[node]=0. if all the DFS directed links are visited I pop ..

## Recent Comments