Questions tagged [dynamic-programming]
Dynamic programming builds solutions from solutions to simpler subproblems. It's closely allied to recursion, but dynamic programming algorithms are formulated as iteration usually over a very regular datastructure.
68 questions
-1
votes
4
answers
738
views
Leetcode: 2327. Number of People Aware of a Secret and Problem with programming skill in general
On day 1, one person discovers a secret.
You are given an integer delay, which means that each person will share the secret with a new person every day, starting from delay days after discovering the ...
-1
votes
1
answer
96
views
Given n points in Cartesian 2D coords and only able to move directly from point to point how can you reach any point while minimising the longest jump
Let's say you're given n points e.g. A(1,2) B(4,2) C(3,1)
How could you reach any of the points from the orign while minimising the longest jump from point to point
For example: A: OA, B: OACB, C: OAC
...
2
votes
2
answers
139
views
Optimal sequence of recipes
I assume the following is/reduces to a known problem, but I haven't been able to find it.
I have a sequence of recipes with associated costs. Each recipe converts a set of resources to another set of ...
1
vote
3
answers
478
views
Algorithm – Number of strings containing every string of a given set a strings
I have a given set S of strings, and a length l, and I am looking for the number of strings of length l that contains every string of S. A naive approach would be to generate every string of length l (...
1
vote
2
answers
280
views
design problem handling a dynamic object
I am writing an application for different geometrical types of fuel tanks.
I have a design problem that only at runtime I will receive the exact type of tank from the end user; and I don't know how ...
0
votes
2
answers
1k
views
Is 'call site' compiler generated auto code?
Is 'call site' some auto code generated by compiler - I come across this term frequently and it sounds like calling method is simply referred as 'call site' - which literally sounds fine but I believe ...
0
votes
1
answer
3k
views
find longest subsequence with sum less than or equal to k
I have a vector<int> num, I want to get the size of longest subarray with the sum less than or equal to k.
My approach:
O(n^2). Repeat for every element in the array.
Can we do better?'
...
3
votes
2
answers
145
views
Overlapping subproblems in immutable languages
Whenever I solve a problem with overlapping subproblems, I reach for memoization because it's so simple to implement. However, memoizing in an immutable language that doesn't have built-in support for ...
1
vote
1
answer
425
views
Dynamic-programming matrix exercise [closed]
I'm practicing with dynamic programming and I'm trying to solve this exercise http://www.geeksforgeeks.org/collect-maximum-points-in-a-grid-using-two-traversals/ But I can't understand how to use ...
-2
votes
1
answer
301
views
Unable to Solve Dynamic Programming
I had an assignment on dynamic programming due last night, but I had to turn it in unfinished because i could not understand how to solve the last problem:
The state wants to monitor traffic on a ...
1
vote
1
answer
917
views
Dynamic Programming: Shortest path with exactly k edges in a directed and weighted graph
I came across this problem of finding the shortest path with exactly k edges. After some searching, I found the code below. It uses a 3D DP. States are there for number of edges used, source vertex ...
7
votes
1
answer
319
views
Finding all possible ways of inserting a pattern into a string
I've been thinking about this problem for a while, and I can only find a recursive solution but I'm feeling that there is a dynamic programming way to do it, I just can't figure it out. Is this a ...
3
votes
1
answer
1k
views
Maximizing Value and Volume, minimizing weight - Knapsack
Trying out a Knapsack variant where the rules are
Any item you take must fit completely in the bag
Usable metrics of the bag are length(l),width(w),height(h) and you can assume that if the products ...
0
votes
1
answer
2k
views
Grid walking explanation [closed]
There's a problem on hackerrank.com called Grid Walking.
Here is its description:
You are situated in an N dimensional grid at position (x1,x2,...,xN). The dimensions of the grid are (D1,D2,...DN)...
7
votes
3
answers
533
views
Picking m number in the best possible time
Imagine we want to pick m numbers from n numbers so that the difference of the maximum and minimum of the m numbers be minimum, for example if
m = 4
n =6
numbers: 10 12 10 7 5 22
The ...
3
votes
5
answers
6k
views
Robot in a grid
This was recently asked to someone I know.
A robot has to move in a grid which is in the form of a matrix. It can go to
A(i,j)--> A(i+j,j) (Down)
A(i,j)--> A(i,i+j) (Right)
Given ...
7
votes
3
answers
9k
views
Number of strings containing a specific substring
I've seen numerous questions (and answers) concerning the number of binary strings (e.g "10010" containing some binary substring (e.g "00"). I'd like to know if there is a way to generalize this:
...
2
votes
2
answers
779
views
Dynamic Programming Problem - To find smallest integer number 'x' which contains only digits 1's and 0's such that x mod n = 0
To design an algorithm that will output the smallest integer number 'x' which contains only digits 1's and 0's such that x mod n = 0 and x > 0.....
For example:
2 divides 10
3 divides 111
4 ...
1
vote
1
answer
150
views
find the minimum number of sets
Let's explain my question with example I have some integer sets for example
S1 = {2,3}
S2 = {2, 5}
S3 = {4, 5}
S4 = {4}
S5 = {5}
And I have sample set Ssample with 4 elements {2, 3, 4, 5}.
So now ...
4
votes
3
answers
3k
views
Finding common prefixes for a set of strings
I am trying to find common prefixes for a sorted set of strings. i.e. if the following strings are given:
AB123456
AB123457
ABCDEFGH
ABCDEFGX1
ABCDEFGY
XXXX
then my function should return three ...
4
votes
1
answer
86
views
How to diversify an optimal solution set?
If given a list of players, their salaries, and their projections, one can easily find the top 'n' projected teams (where a team is a combination of players), such that every team is under the salary ...
1
vote
2
answers
142
views
Need to organize words based on their components, any other way aside from brute force?
I'm not sure if this process has a name.
I have some words (about 9,000). They are in Japanese, but I'll try to explain this using English words. I want to categorize the words by the components (in ...
-1
votes
1
answer
526
views
How to solve linear recurrences involving two functions?
Actually I came across a question in Dynamic Programming where we need to find the number of ways to tile a 2 X N area with tiles of given dimensions..
Here is the problem statement
Now after a bit ...
1
vote
2
answers
1k
views
Finding lowest cost path - dynamic
I have to write a dynamic algorithm for finding lowest cost path. So I have a point that I have to visit. I can jump only between points by distance - 5 I have an array of distance from 0-point for ...
0
votes
2
answers
87
views
Is array dependence on previous terms considered recursive?
For example, take the case of Fibonacci number to calculate nth number you require n-1 and n-2 term.
If I do it with bottom up approach, is it recursion as f(n) depends on f(n-1)?