Questions tagged [dynamic-programming]
Dynamic programming is an algorithmic technique for efficiently solving problems which have recursive structure with many overlapping subproblems. Do NOT use this tag for general "dynamic" behavior in code.
dynamic-programming
5,695
questions
0
votes
1
answer
44
views
Leetcode 1255-recursion and backtracking
I dont quite understand why have we used .clone() method when we have a second for loop to restore the letterCount.And when i'm runnig this code without .clone() method its giving me the wrong answer? ...
-1
votes
1
answer
69
views
Can dynamic programming help solve this problem? [closed]
Note - If you have other approach that works better than DP then please suggest them.
I have a 2D list like this [ [1,2], [1,2], [1,3], [5,4], [4,6] ]. I want to flatten this to a 1D list such that ...
0
votes
2
answers
47
views
How to dynamically switch between two images onclick in Vue.js
I am trying to switch images on click in Vue.js. My code isn't working but this is what I am trying to make happen:
On load the image is black, after clicked/selected the image switches and turns into ...
1
vote
1
answer
129
views
Is there a optimal solution for Jump Game Problem using C programming
PROBLEM DESCRIPTION
You are given an integer array. You are initially positioned at the array's first index, and each element in the array represents your maximum jump length at that position.
Return ...
0
votes
0
answers
47
views
2 City Scheduling DP clarification
For the following problem from leetcode, would it be possible to structure my recurrence relation like this for using a DP approach:
OPT[i][w] = min{cost[I][0] + OPT[I+1][w-1], costI + OPT[I+1][w]}
...
3
votes
4
answers
141
views
How to find min cost for element selection from a sequence of adjacent pairs
Given an array of integers (with at least two elements), I need to choose at least one element of each adjacent pair of elements in the array in a way that costs me the least. Then, return the cost ...
0
votes
1
answer
26
views
Number of hits in fibonacci using lru_cache
I am using functools.lru_cache to implement Fibonacci using memoization. But I do not understand the number of hits that my output generates. My code is as follows:
@lru_cache(maxsize=8)
def fib(n):
...
0
votes
1
answer
104
views
jit - "Failed in nopython mode pipeline" error, despite not using nopython in numba
I am using value function iteration to solve a complex dynamic programming problem with many states. I want to use numba/jit to speed up my code (and eventually parallelize the for loops). When I use ...
0
votes
1
answer
23
views
Issue solving DFS Flood Fill problem while iterating through branching options
I am learning Dynamic Programming and am trying to solve the Leet Code Flood Fill problem.
I came up with this solution, but it doesn't recurse correctly through all the possible moves.
Given the ...
0
votes
0
answers
11
views
Discrepancy in Recursive and Memoized Knapsack Solution
I'm currently working on a knapsack problem and have implemented both a recursive solution without memoization and a memoized version. Surprisingly, the recursive solution is giving me the correct ...
-1
votes
1
answer
194
views
Dynamic Programming - Elevator Rides CSES
Here is the problem:
There are n people who want to get to the top of a building which has only one elevator. You know the weight of each person and the maximum allowed weight in the elevator. What ...
1
vote
3
answers
80
views
Update every nth element of given a range
I have N=12
and between 1 to 12 (in N) I want every 3 elements to be updated.
For example:
I am calculating the current hour(say 6am) and add 4 hours to start with "6-10" for the 1st 3 rows ...
0
votes
1
answer
229
views
Maximum-value partition using Dynamic programming
Suppose we are given an array A[1..n] of integers (some positive and some negative) which we
are asked to partition into contiguous subarrays called segments. The value of any segment is the
product ...
1
vote
1
answer
164
views
Minimum Time to Perform One Task of Each Category (with Different Release Times)
I've recently taken an OA in which you needed to write an algorithm for finding the earliest time at which you were able to complete one task from each category. Each task has a duration and a time at ...
0
votes
1
answer
150
views
Trouble Solving Maximum Product Subarray
I am trying to solve LeetCode problem 152. Maximum Product Subarray:
Given an integer array nums, find a subarray* that has the largest product, and return the product.
The test cases are generated ...