All Questions
Tagged with dynamic-programming math
104
questions
1
vote
1
answer
83
views
all possible distinct non decreasing sequences(combinations) of numbers to reach the given sum with quick performance
I need to count all possible combinations of numbers to reach the given sum.
They should be non decreasing(every next number should be greater or equal to previous one).
Here is JavaScript code with ...
2
votes
1
answer
900
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 ...
-1
votes
1
answer
94
views
LeetCode Climbing Stairs
I tried to separate the climbing scenarios into scenarios of how many 2 steps can be taken and to solve the question according to the sum of the combinations of the moments where 2 steps can be taken ...
1
vote
1
answer
155
views
Recurrence relation for T(n) of Top-Down approach solution of Fibonacci sequence
What is the recurrence for T(n) of this code and the initial conditions of this recurrence? Notice that the code is in python and it is a top-down procedure solution for the Fibonacci sequence 0, 1, 1,...
-1
votes
1
answer
83
views
Can we solve this using dynamic programming?
Find the number of subsequences of size n, with sum such that after taking modulo m, the sum became greater or equal to x.
Where:
1 <= n <= 42
1 <= m <= 10^9
0 <= x < m
How to solve ...
2
votes
1
answer
552
views
Time complexity of recursive function that calls two halves floor(x / 2) and ceil(x / 2)
I have a function f(x) that calls f(x / 2) if x is even and calls both f((x + 1) / 2) and f((x - 1) / 2) if x is odd. Note that f(1) = constant and we don't recurse further than f(1). (So, it can be ...
1
vote
1
answer
117
views
Trouble finding the smallest number of 1's required to represent an integer
I'm doing some programming challenges for fun and I've gotten really stuck on one particular problem regarding how to represent integers using only ones. The question is what is the least number of ...
0
votes
2
answers
1k
views
Leetcode: Stone Game (How can I code it differently)
Problem statement:
Alice and Bob play a game with piles of stones. There are an even number of piles arranged in a row, and each pile has a positive integer number of stones piles[i].
The objective ...
2
votes
1
answer
333
views
How to solve M times prefix sum with better time complexity
The problem is to find the prefix sum of array of length N by repeating the process M times. e.g.
Example N=3
M=4
array = 1 2 3
output = 1 6 21
Explanation:
Step 1 prefix Sum = 1 3 6
Step 2 prefix sum ...
2
votes
2
answers
641
views
Largest subset from set of numbers (also negative) having sum equal 0
I have a huge set of numbers with a defined order. The logic in simple terms would look like this:
data['values'] = [1,1,3,4,4,-9,10]
data['order'] = [1,2,3,4,5,6,7]
ExpectedSum = 0
What I wish to ...
-3
votes
2
answers
80
views
Summing arrayelements up with init, elements, steps [closed]
Hi Im searching a fast dynamic programming / formula solution. For following algorithm, example:
init := 1
elements := 4
steps := 3
step 1. [1,1,1,1] init is placed in each index
step 2. [1,2,3] index ...
3
votes
1
answer
353
views
To which Knapsack-problem variation does this problem correspond?
Let us imagine that I have to fill my knapsack with items under constraints:
Each item has an associated weight wi and profit pi
With a maximum total weight Wmax
Knowing that:
There are categories ...
1
vote
3
answers
3k
views
Given a rod of length N , you need to cut it into R pieces , such that each piece's length is positive, how many ways are there to do so?
Description:
Given two positive integers N and R, how many different ways are there to cut a rod of length N into R pieces, such that the length of each piece is a positive integer? Output this answer ...
1
vote
1
answer
987
views
Finding the minimum set of coins that make a given value
I've been trying to figure out if there would be a way to get the optimal minimum set of coins that would be used to make the change.
The greedy algorithm approach for this has an issue such as if we ...