Dynamic programming is an algorithmic technique for efficiently solving problems with a recursive structure containing many overlapping subproblems.
4
votes
2answers
103 views
Finding all the subsets in an array of integers that sum to a given target
Problem Statement:
Given an Array if ints, Find out all the subsets in the Array that
sum to a given target value.
Example:
If the input array is:
...
5
votes
1answer
250 views
Minimum number of coins - (dynamic programming solution - topdown approach)
This is a problem from topcoder tutorials
Given a list of N coins, their values (V1, V2, ... , VN), and the total sum S. Find the minimum number of coins the sum of which is S (we can use as many ...
9
votes
1answer
135 views
Reading, processing and counting an array setting limits
Last weekend my teacher asked me to create code to solve a problem:
Giving a dynamic array, we want to pass the array elements from a file. The first number in the file N gives us the array ...
0
votes
1answer
188 views
Solving the rod-cutting problem using dynamic programming
I've written what I believe is a valid dynamic programming solution to a variation of the rod cutting problem. In this problem, the goal is to make as few cuts as possible on a rod of length n.
I ...
1
vote
0answers
144 views
DP algorithm to find minimum average wait for customer-serving system
Below is the code to find the minimum average waiting time for customers at a store. I want improve the time complexity of the code. As an overview of the logic, I start from ...
5
votes
1answer
119 views
Optimizing a dynamic programming solution for “Oil Well”
I'm trying to solve the Oil Well problem on Hackerrank using dynamic programming and it works. However, it times out for some of the test cases. I wanted to know how this program can be improved so ...
1
vote
1answer
109 views
Coin problem through brute force
I have some code that will brute force solve the following problem:
Given a set of x coins and a target sum to reach, what is the fewest number of coins required to reach that target?
The code ...
7
votes
1answer
308 views
Project Euler #14 — longest Collatz sequence
I was reading this question and realized that I didn't know Python well enough to critique the algorithm. So I wrote a Java solution instead, which is inappropriate for that question. Since there's ...
3
votes
1answer
158 views
Calculate possible balances in piggy-bank by weight
I have solved Piggy-Bank problem on SPOJ using dynamic programming.
The question asks you to get the minimum value that is possible with given weight (\$w\$) and one or more coins (\$n\$) with given ...
5
votes
1answer
113 views
Word break problem with dynamic programming
This is the original question.
I have implemented it in both ways. If I enter the word "icecream", should I output "ice" "cream" and also "icecream", or just "ice" and "cream"?
Is this a good ...
2
votes
1answer
54 views
Memoization for calculating minimal traversal distance within a positive matrix
The code below is for calculating the minimal traversing distance from the top left point of the matrix to the bottom right point of the matrix.
GitHub
Here is the core functionality. Please note ...
3
votes
1answer
144 views
Google CodeJam Round D APAC Test
Problem A:
Vincenzo decides to make cube IV but only has the budget to make a square maze. Its a perfect maze, every room is in the form of a square and there are 4 doors (1 on each side of the ...
3
votes
1answer
119 views
Dynamic Programming for printing additive numbers up to digits n
Edit: I am hoping to get some review / make sure I am understanding dynamic programming correctly.
I am trying to print out all additive numbers up to digits n using dynamic programming. Additive ...
3
votes
2answers
219 views
Longest Common Subsequence and Longest Subsequence Palindrome
The following code computes:
The longest common subsequence between two strings, where a subsequence of a sequence does not have to consist of contiguous elements of the sequence.
The longest ...
8
votes
3answers
325 views
Handling shared state among a lot of elements in Angular
I am working on a project in Angular where I have a number of similar data objects. When you click on anyone of them it's state and amount of data shown will change. All of the objects start in the ...
1
vote
2answers
251 views
Longest collatz sequence using dynamic programming
I am trying to solve longest collatz sequence problem under 1000000 with the below code. Can anyone suggest a faster way to approach this problem? I was thinking of dynamic programming, but I'm ...
4
votes
3answers
493 views
Project Euler 81 (minimum path sum through a matrix)
Problem Statement:
In the 5 by 5 matrix below,
131 673 234 103 18
201 96 342 965 150
630 803 746 422 111
537 699 497 121 956
805 732 524 37 331
...
11
votes
3answers
765 views
Substitution cipher algorithm performance boost
This algorithm is meant to read a string of numbers on an input, a naive substitution cipher code (A = 1, B = 2, ..., Z = 26) and output the number of ways the code could be interpreted (e.g. 25114 ...
1
vote
2answers
90 views
Making operations more dynamic
I am trying to build something that will allow us to configure "custom" validation for each customer. So if a customer wants to see a value contain a specific char, be specific length, or equal ...
3
votes
1answer
818 views
Determining maximum profit to be made from selling shares
Question
Your algorithms have become so good at predicting the market that you
now know what the share price of Wooden Orange Toothpicks Inc. (WOT)
will be for the next \$N\$ days.
...
2
votes
2answers
120 views
Calculating the number of prime numbers to solve the puzzle
How can the following program execution time improved? I have used dynamic programming in both "recursive" as well as "prime" function, but I'm not getting the efficient execution time.
There is ...
11
votes
5answers
2k views
Dynamic programming with Fibonacci
I have written the following code using a dynamic programming technique. Can I use ArrayList here? Please let me know if I can improve this code.
...
4
votes
1answer
93 views
NGON (many polygons) on SPOJ
I am trying to solve NGON problem. I am using bottom up dynamic programming here. Recurrence function is:
$$\begin{array}{rl}
f(a,b) &= f(a-1,b) + f(a-1,b-1)\,a_i ...
10
votes
1answer
91 views
Loading Data Warehouse with Dynamic SQL
For a data warehousing project I ran into the following:
Custom fields that users can create, modify and delete, that should be loaded into the data warehouse as they are when the ETL happens.
On ...
2
votes
1answer
214 views
Determine if subset in int array adds up to a given input integer
Given a set of non-negative integers, and a value sum, determine if there is a subset
of the given set with sum equal to given sum. On similar lines, Partition problem is to determine whether a given ...
4
votes
2answers
139 views
The Three-machine proportionate flow shop problem with unequal machine
As part of an Academic project I wrote the following code, according to the algorithm (verbal). When I checked the rest of the article I notice that the efficiency should be \$O(n^2)\$ and I wrote ...
4
votes
1answer
167 views
Dynamic programming with Project Euler #18
I just wanted to get an opinion on my dynamic-programming Haskell implementation of the solution to Project Euler problem 18.
The Problem:
By starting at the top of the triangle below and moving ...
5
votes
2answers
2k views
Optimizing O(m n) solution for longest common subsequence challenge
Given two strings string X of length x1 and string Y of length ...
7
votes
1answer
144 views
Three-machine proportionate flow shop problem with unequal machine
As part of an academic project I wrote a code about dynamic programming that solves the "Three-machine proportionate flow shop problem with unequal machine".
In flow shop scheduling it is usually ...
10
votes
3answers
555 views
Optimizing “Herd Sums” problem using dynamic programming
I'm trying to solve a practice problem and all is well except for the last 2 inputs my solution is too slow. Just one loop is slowing it down I think.
Herd Sums
Execution Time Limit: 2 ...
5
votes
2answers
650 views
Finding alternating sequence in a list of numbers
Please be brutal and treat this as me coding this up for an interview.
A sequence of numbers is called a zig-zag sequence if the differences between successive numbers strictly alternate between ...
7
votes
1answer
401 views
Assembly line scheduling
This is solution to the assembly line problem. Here is complete description, which is too big and verbose to re-describe. I apologize for the inconvenience of the hyperlink.
Note: I do understand ...
1
vote
1answer
109 views
Knapsack 01 solution
Solution to bounded knapsack 01 problem. Once again comprehensive description is difficult in this space, refer here. Looking for code review. optimizations and best practices.
...
4
votes
2answers
118 views
Returning all the LIS of given array of int
I have this assignment where I'm supposed to code an algorithm for finding the quantity of Longest Increasing Subsequences from an array of (different) integers and print them all.
I developed one ...
1
vote
1answer
471 views
MaxSum sub matrix within a matrix
Code review for best practices, optimizations, code cleanup etc. Also requesting verification of the complexity: O(row*row*col).
...
5
votes
2answers
469 views
Box-stacking problem in C++
I have tried to write code of Box stacking problem (mentioned here) in C++ .
Kindly give me some views on what mistakes I might have made and how I can improve.
It is running for the two inputs I have ...
2
votes
1answer
466 views
2
votes
1answer
395 views
Jump game in Java
Looking for code review, suggestions for improvement, best practices etc.
The problem definiton is
Jump Game
Given an array start from the first element and reach the last by jumping. The ...
2
votes
1answer
667 views
Project Euler #15 — count possible lattice paths
I'm not a C programmer, just wanted to make a fast solution to the problem.
Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 ...