5,714 questions
-3 votes
0 answers
56 views
Can we solve the following optimization problem by dynamic programming [closed]
Suppose we have an π*π grid, let π=0,...,πβ1 and π=0,...,πβ1. For each grid point we have an array πππ of size π that serves as local score function. We want to to find a way that assigns ...
-3 votes
0 answers
58 views
Cross-Platform Quantum Bitmask Pathfinding Challenge [closed]
You are given a NΓNNΓN 2D grid representing possible quantum states, where each cell contains a 32-bit unsigned integer. Your task is to find a continuous path from the top-left (0,0) to bottom-right (...
5 votes
1 answer
288 views
Efficient algorithm to count contiguous subarrays that can form arithmetic progressions
I'm working on a problem where I need to count, for each possible common difference D, the number of contiguous subarrays whose elements can be rearranged to form an arithmetic progression with common ...
0 votes
0 answers
74 views
Why this code for 0/1 knapsack problem works for some examples?
Problem Statement There are N items, numbered 1, 2, β¦, N. For each item i (1 β€ i β€ N): It has a weight w[i] It has a value v[i] Taro wants to choose some of these N items and carry them home in a ...
2 votes
1 answer
193 views
how to decide forward or backward computation in dynamic programming tabulation
I do not know when to use backward or forward computation for tabulation in solving a dynamic programming problem. I would like to know the thinking process to decide which one to use or which one ...
-4 votes
1 answer
273 views
How to count the number of subset partitions of {1..n} into two equal-sum subsets (modulo 10βΉ+7) [closed]
I'm working on a combinatorics problem where I need to compute how many ways the set {1, 2, ..., n} can be divided into two subsets with equal sum, such that every number from 1 to n is in exactly one ...
0 votes
1 answer
112 views
Time complexity of dynamic programming
I'm looking at one of the solutions to the programming problem: Partition a Set into Two Subsets of Equal Sum. The programming problem: Given an array arr[], the task is to check if it can be ...
1 vote
1 answer
106 views
Anyone know the right algorithm? [closed]
Does anyone know any LeetCode, Codeforces or anything like the following programming problem?: Imagine you have "n" slots, from 1 to "n" with "s" being your starting ...
9 votes
2 answers
264 views
Given Input strings A, B and C, determing if C is a valid shuffle of A and B
A valid shuffle of two strings A and B is when their characters are mixed together to form a bigger string and all characters are used and the string is such that the order of characters in A and B is ...
-1 votes
1 answer
69 views
What is correct path tracking in Floyd-Warshall algorithm?
There are several descriptions of the Floyd-Warshall algorithm, including the one in Wikipedia where path tracking logic described like in the pseudo-code below (copy from Wikipedia https://en....
0 votes
1 answer
88 views
Why does int in my DP array cause overflow in Coin Change II problem?
class Solution { public: int change(int amount, vector<int>& coins) { vector<unsigned int > dp(amount+1, 0); dp[0]=1; for (int value: coins){ ...
5 votes
2 answers
133 views
Getting all distinct subsets from subset sum problem with target T using Dynamic Programming
In the classic subset sum problem, there are a set S and a target t, and the goal is to find a subset of S whose sum is t. This variant has a pseudo-polynomial time solution. In a variant of the ...
6 votes
1 answer
178 views
Struggling with bottom up approach for This Kattis Problem: The mailbox manufacturers
Problem description: A mailbox manufacturer wants to test a new mailbox prototype's durability based on how many fire crackers it can withstand. Given k identical mailboxes (each holding up to m ...
0 votes
0 answers
44 views
how to return dynamic columns with multiple records with out passing a columns to functions returning "record" in PostgreSQL [duplicate]
I have a table like below create table public.test_dynamic_data_tbl(col1 int,col2 character varying,col3 double precision); insert into public.test_dynamic_data_tbl values(1,'test1',12) insert into ...
0 votes
0 answers
55 views
Valid Parenthesis String, Recursion with memoization to DP
How can the following recursion + memoization code be converted into a tabulation format dynamic programming solution? The code is working but I want to improve it. The challenge I am facing is ...