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.
5,600
questions
0
votes
0
answers
8
views
software oriented problem in dynamic memory
I need to develop code for a software-oriented problem, but not an end-user application or program. I need a computing problem, something that is managed within memory, that deals with the data in ...
-1
votes
0
answers
11
views
What shld be the appropriate size of memoization in Dynamic Programming whether it shld be dp=[0]*n or dp=[0]*n+1?
i was doing some leetcode problem and in some question they use dp=[0]*n and in others they use dp[0]*n+1
I tried using both of them but still a lot of confusion persists, can you please give me a ...
1
vote
0
answers
56
views
Time complexity increased by using memoization when I use map<pair<int,int>,int> to store the DP state
I was solving the CSES-Apple Division Problem. It was a dp sum difference minimization problem. We have to divide an array into two subsets whose sum difference is minimum.
I was using basic Recursion ...
0
votes
0
answers
34
views
rod cutting problems in recursive method. Why dose ` p[i]+ rodCutting(n-i) ` works?
When I learn the dp,the first example I encountered was rod cutting problem with its not smart method.
I just confused with the steps when cut the original rod into two pieces, it just get the maximum ...
-1
votes
0
answers
64
views
Dynamic programming problem: Frogs in Stones [closed]
I have the following dynamic programming problem (to solve in python or java):
Frogs jump stones
There are some frogs that do not like water and spend their time jumping from stone to stone. Suppose a ...
1
vote
0
answers
72
views
Find best path maximizing score in 2D array
I’m trying to implement a game where the allowed moves are left to right and top to down in a N x N 2D array with random positiv floats and a null trace (0 in diagonal). The moves are not restricted ...
-2
votes
0
answers
29
views
Dynamic programming problem: Possible solutions in wich frogs can be placed in stones [closed]
I have this problem of dynamic programming: we have p stones, r frogs, m movements, and a configuration in which these frogs are initially placed on the s stones. An example of this entrance would be: ...
0
votes
1
answer
55
views
General Memoization function in F#
I have a question about this general memoization function in Fsharp:
let memoize f =
let dict = new Dictionary<_,_>()
fun n ->
match dict.TryGetValue(n) with
| (true, ...
0
votes
0
answers
19
views
Time Complexity Analysis for a Plant Positioning Algorithm
Please verify my understanding, but I believe the time complexity of this solution can be described as O(row * column * column) due to the presence of Math.min() and array.slice() operations within a ...
0
votes
0
answers
33
views
Traveling Salesman Problem (Dynamic Solution)
I have managed to implement a dynamic TSP algorithm and the code works and runs but it produces the wrong output for larger data sets
This is my code
//TSP Dynamic Application
public static ...
1
vote
1
answer
36
views
GEKKO / IPOPT - NL Optimization becomes unfeasible because of a change in exponent
I am attempting to run a dynamic optimization model in discrete time with GEKKO and IPOPT (v3.10.2). My model is the following :
from gekko import GEKKO
import numpy as np
# Simulation time
T = 5 ...
0
votes
1
answer
28
views
Is it possible in Angular 13 to deploy build in different domain having different apiURL without rebuilding the application?
I am working on a functionality in which i will make a build for DEV environment and deploy on DEV domain . Further , without rebuilding the application again for QC environment , i want to make use ...
0
votes
0
answers
9
views
Trensalte the pop up of close appointment
I am working in Dynamics 365 (D365), and I would like to modify the label of the "Close Activity" pop-up. Specifically, I want to change the label associated with the button named "[...
0
votes
1
answer
33
views
dungeon problem using dp recursive approach
This is the Question...
The following problems revolve around an adventurer who enters a dungeon in search of Gold
(Treasure). The objective for all the questions will be to find the quickest path to ...
1
vote
1
answer
55
views
Number of ways to color houses with no 2 equal colors next to each other and symmetry constraint
There are n houses along the street, and we need to color every with one of 3 colors but there are 2 constraints:
Adjacent houses need to have different colors
Symmetric houses cannot have the same ...
2
votes
4
answers
173
views
Given an array of N integers, return the max sum of 3 NON-adjacent elements
I got this question for a coding interview (mock, part of my uni's competitive programming club since a few people are curious lol), and I got stuck on finding the optimal solution. Extra details/...
0
votes
1
answer
52
views
Error in Making Change using Dynamic Programming in c
Well i have tried it many time and still unable to find the error in the code below it is making change proble using dynamic programming need help to eliminate the wrong output and if possible plz ...
1
vote
1
answer
29
views
Getting Run Time error for a Kattis Problem(robotsonagrid)
I am trying to solve this problem (https://open.kattis.com/problems/robotsonagrid).
And when I submit my final code I keep getting a Run Time error in Test case 4. I am not sure what's wrong with my ...
4
votes
1
answer
116
views
Maximum Profit for selling/buying stocks but we can only have absolute value of at most k shares
I have a classic interview problem to ask but it is with a twist:
You are given the stock prices for n days, a1, a2, ..., an. You are also given an integer 1 <= k <= n. Each day, you can do one ...
1
vote
0
answers
57
views
How to find least number of moves to swap adjacent colored tiles on 2D grid so that no colors are adjacent?
Sam recently hired a tile installer to tile a kitchen floor. The floor was supposed to be very colorful with no two adjacent tiles having the same color. Unfortunately, the installer failed to ensure ...
-1
votes
1
answer
54
views
"Coin change 2": Why is this dynamic programming implementation not efficient enough? [closed]
I am working on a LeetCode problem, 518. Coin Change II:
You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money.
...
-1
votes
1
answer
30
views
Adding memorization (dp) to my recursive code gives different result which is wrong
I have been stuck on this LeetCode problem Number of increasing paths in a grid:
You are given an m x n integer matrix grid, where you can move from a cell to any adjacent cell in all 4 directions.
...
1
vote
0
answers
19
views
Inconsistent output on leetcode and vs code [duplicate]
class Solution:
def combinationSum4(self, nums: List[int], target: int,memo={}) -> int:
if target in memo:
return memo[target]
if target==0:
return 1
...
1
vote
1
answer
88
views
Delphi function SetProperty (ComponentName: string, PropertyName: string, JSONValue: string): boolean;
How would I go about to write a function that takes the name of a component and property and a JSON value string and populate that component's property with the value dynamically?
The property can be ...
0
votes
1
answer
95
views
Ideal Profits in companies in Perfect Binary Search tree
I'm trying to solve the following problems here:
In the X world, companies have a hierarchical structure to form a large binary tree network (can be assumed to be a perfect binary tree). Thus every ...
1
vote
3
answers
70
views
Every Potential Combination of a Number from a List
I'm attempting to generate all conceivable combinations of a given number using elements from a list. For instance, when the number is 4 and the list contains [1, 2], there are 3 possible combinations:...
0
votes
2
answers
118
views
Optimization of matrix search
I have a matrix of 6 columns and 375 rows, the user sets any number. The task is as follows, find all combinations in which a number is taken from each column (a total of 6 numbers) and their sum ...
0
votes
0
answers
24
views
Trying to write an iterative dynamic programming solution to the travelling salesman problem (python)
I'm trying to write an iterative dynamic programming solution to the travelling salesman problem, building up the solution from the solutions to subproblems. However, I am finding this a bit ...
0
votes
1
answer
30
views
I was trying to solve this question on GFG. Can anyone please tell me what is wrong with my code?
Geek's Journey
You're provided with two arrays:
"geeksTown" of length n - representing the heights of buildings in
Geek's town "journey" of length m - representing the ...
1
vote
0
answers
26
views
How can I write the output stream of sddp.jl into an excel file?
I am using sddp.jl for my research project in which I am developing a state-of-the-art actor critic algorithm which I am going to benchmark with SDDP but for it I need to plot graphs which require ...
-1
votes
1
answer
57
views
Finding the Maximum and Minimum Number of Operations to Delete all Element in a Circular List
In a circular list of length n, where a1 is adjacent to a2, a2 is adjacent to a3, and an is adjacent to a1. Each operation can delete one number, after each deletion, if there exists adjacent equal ...
0
votes
1
answer
33
views
Boolean Parenthesization Problem's code is not working
Regarding the "Boolean Parenthesization" problem, my code doesn't work. I tried the approach using the dynamic approach, however for the the input of N=5 and T^F|F, I got 0 as the output but ...
1
vote
0
answers
81
views
Why does my solution not work for coin change problem?
At every recursive call I choose 1 more of current denomination or no more of current denomination. I sort the denominations in descending order and use a cache of seen remaining amount. Since I try ...
4
votes
0
answers
55
views
Is there any true general pattern to solve any dynamic programming problems?
I understand there is a general pattern to solve dynamic programming problems. Consists of:
Identify Overlapping Subproblem by Breaking down the problem into smaller subproblems that are solved ...
3
votes
1
answer
225
views
Find the maximum sum of all contiguous subarrays and not consecutive each others which its length at most 'k' in a given array
Problem: Given an array 'arr' and an integer 'k', find the maximum sum of all subarrays of 'arr' whose size is at most 'k'. Note that you can't choose subarrays which are consecutive or overlap each ...
0
votes
0
answers
25
views
Solution works in Code Editor but not in LeetCode [duplicate]
I'm currently doing the "Word Break" problem in LeetCode. It is a dynamic programming problem with the difficulty "Medium". For some extrange reason, the exact code (but without ...
-4
votes
1
answer
51
views
Why this shortest pathfinding algorithm not working?
Trying to find the shortest path through a dynamic programming approach
but it doesn't seem to be working below is the code of the algorithm and the graph class.
I tired to store the paths through a ...
-1
votes
1
answer
48
views
Why --i and i-1 producing diffrent output in recursion?
I have two method, the difference is one is having --i1 and other is having i-1, however they are producing different output.
String s1 = "axbdcg";
String s2 ="...
0
votes
0
answers
22
views
combinatorics problem-number of game outcomes
There are m concentric circles, and n straight lines through the center point, intersecting each concentric circle at 2n points. Let the outermost two adjacent intersections be A and B. Alice and Bob ...
0
votes
1
answer
17
views
GridTraveler tabulation error making all elements of the table 0 in js
this is the tabulated version of gridTraveler, where you output the number of ways one can travel from the top left to the bottom right corner in an m*n box, but you can only move down or right.
const ...
0
votes
1
answer
106
views
API in Dynamics AX 2012
I have a problem in AX 2012 when I call API by Https URL give me this error
(The request was aborted: Could not create SSL/TLS secure channel)
but when I test code in Dynamic 365 It Work
This My code:
...
1
vote
0
answers
110
views
minimum number of operations to get a target number
If there is a list of digits in string format, e.g. ["1", "5", "8"], list of valid operations are "+","-", and "*" and a target number. Find ...
4
votes
2
answers
118
views
Count ways to reach end from start stone and come back, without taking using the same stone twice with at most K jumps at each step
Richard is a penguin who regularly commutes between Canada and the United States.
Specifically, Canada is at location 1
, and the United States is at location N.
In locations 2 through N, there are ...
-1
votes
1
answer
19
views
Given an array of integers, how can I assign the ints to two different arrays that have a capacity?
You're given a list of integers, you must add the integers to one of two lists, each of these lists has the same capacity that the sum of ints inside the list must be under.
This is just a rough ...
0
votes
1
answer
41
views
Max Sum in array excluding adjacent numbers
maximum sum of an integer array such that if we consider an element a[i] then we should not consider a[i]-1 and a[i]+1. for example if array a = [1,1,1,1,1,2,2] the o/p = 5 and if a = [3,3,3,4,4,8,1] ...
0
votes
1
answer
46
views
Python acting in a strange way (Dynamic Programing) [duplicate]
I have written this following code that takes an integer N and and array of integers: arr. The task is to find the shortest combination of the integers in arr that sum up to N . Each elements of arr ...
0
votes
1
answer
49
views
in gdscript how do you get the toggled function to do something when a checkbox is clicked in the godot engine
in gdscript (using godot 4.1.1 stable) i am working on a function that adds a checkbox dynamically works fine
but when i try to get it to do something when it is toggled i get all sorts of errors this ...
-2
votes
1
answer
51
views
Bool condition checks gives warning
I am trying to solve a problem here https://leetcode.com/problems/word-break/ . My code looks like below:-
bool existsInDict(string s, vector<string>& wordDict)
{
if(std::find(wordDict....
0
votes
0
answers
46
views
Counting Subproblems in Dynamic Programming?
Taking a class on algorithms - trying to understand what is meant by the 'count of a subproblem' when discussing dynamic programming.
The scenario I'm faced with is as such:
An investor wants to ...
0
votes
1
answer
37
views
Printing minimum path sum path (matrix)
Solving [leetcode problem][1] which is as follow:
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.
...