Skip to main content

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.

Filter by
Sorted by
Tagged with
-1 votes
4 answers
738 views

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 ...
jason's user avatar
  • 15
-1 votes
1 answer
96 views

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 ...
DanielKel's user avatar
2 votes
2 answers
139 views

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 ...
Rasmus Faber's user avatar
1 vote
3 answers
478 views

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 (...
jthulhu's user avatar
  • 141
1 vote
2 answers
280 views

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 ...
moshiko netzer's user avatar
0 votes
2 answers
1k views

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 ...
rahulaga-msft's user avatar
0 votes
1 answer
3k views

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?' ...
Nygen Patricia's user avatar
3 votes
2 answers
145 views

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 ...
Drathier's user avatar
  • 2,883
1 vote
1 answer
425 views

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 ...
Haring's user avatar
  • 19
-2 votes
1 answer
301 views

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 ...
WoernerBro's user avatar
1 vote
1 answer
917 views

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 ...
Dhruv Mullick's user avatar
7 votes
1 answer
319 views

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 ...
Daniel Olsson's user avatar
3 votes
1 answer
1k views

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 ...
Vrashabh Irde's user avatar
0 votes
1 answer
2k views

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)...
Andrey Chernukha's user avatar
7 votes
3 answers
533 views

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 ...
Amen's user avatar
  • 135
3 votes
5 answers
6k views

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 ...
Vrashabh Irde's user avatar
7 votes
3 answers
9k views

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: ...
Meri Craig's user avatar
2 votes
2 answers
779 views

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 ...
redDragon's user avatar
  • 105
1 vote
1 answer
150 views

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 ...
Daniel.V's user avatar
  • 119
4 votes
3 answers
3k views

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 ...
cruppstahl's user avatar
4 votes
1 answer
86 views

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 ...
Bam Bam's user avatar
  • 49
1 vote
2 answers
142 views

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 ...
Lathan's user avatar
  • 21
-1 votes
1 answer
526 views

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 ...
Aditya Bahuguna's user avatar
1 vote
2 answers
1k views

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 ...
jondetra's user avatar
0 votes
2 answers
87 views

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)?
user3254095's user avatar