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
4
votes
2
answers
3k
views
Dynamic Programming: Number of ways to get at least N bubble sort swaps?
Let's say I have an array of elements for which a total ordering exists. The bubble sort distance is the number of swaps that it would take to sort the array if I were using a bubble sort. What is ...
21
votes
7
answers
29k
views
What is a good algorithm for getting the minimum vertex cover of a tree?
What is a good algorithm for getting the minimum vertex cover of a tree?
INPUT:
The node's neighbours.
OUTPUT:
The minimum number of vertices.
7
votes
3
answers
3k
views
Has anyone seen a programming puzzle similar to this?
"Suppose you want to build a solid panel out of rows of 4×1 and 6×1 Lego blocks. For structural strength, the spaces between the blocks must never line up in adjacent rows. As an example, the 18×3 ...
24
votes
14
answers
18k
views
Algorithm to Divide a list of numbers into 2 equal sum lists
There is a list of numbers.
The list is to be divided into 2 equal sized lists, with a minimal difference in sum. The sums have to be printed.
#Example:
>>>que = [2,3,10,5,8,9,7,3,5,2]
>&...
3
votes
3
answers
1k
views
How can I implement this equation in Java?
OK, this is more of a follow-up question: How to compute optimal paths for traveling salesman bitonic tour?
First of all, for the bitonic tour of the traveling salesman problem I have the following ...
16
votes
2
answers
15k
views
How to compute optimal paths for traveling salesman bitonic tour?
UPDATED
After more reading, the solution can be given with the following recurrence relation:
(a) When i = 1 and j = 2, l(i; j) = dist(pi; pj )
(b) When i < j - 1; l(i; j) = l(i; j - 1) + dist(pj-...
1
vote
1
answer
853
views
Dynamic Programming Recursion and a sprinkle of Memoization
I have this massive array of ints from 0-4 in this triangle. I am trying to learn dynamic programming with Ruby and would like some assistance in calculating the number of paths in the triangle that ...
11
votes
8
answers
9k
views
Is this variant of the subset sum problem easier to solve?
I have a problem related to the subset sum problem and am wondering if the differences make it easier, i.e. solvable in a reasonable amount of time.
Given a value V, a set size L, and a sequence of ...
6
votes
1
answer
574
views
When have you used dynamic programming in the field?
When have you ever directly applied the concepts of dynamic programming to solve a problem in the field? It's sometimes not evident how it can be applied when using it to solve a made-up instance of ...
4
votes
5
answers
1k
views
How does this C++ function use memoization?
#include <vector>
std::vector<long int> as;
long int a(size_t n){
if(n==1) return 1;
if(n==2) return -2;
if(as.size()<n+1)
as.resize(n+1);
if(as[n]<=0)
{
as[n]=-4*...