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
0
votes
2
answers
109
views
Dynamic Programming - Minimum cost to fill given weight in a bag
We are given an array of positive weights cost where cost[i] represents the cost of filling i + 1 kg's of oranges in a bag (0-based indexing). We need to find the minimum cost to buy exactly w kg's of ...
4
votes
3
answers
247
views
Minimum Cell Changes to Ensure Unique Numbers in Each Row and Column of an n×n Table
We have an n×n table, and in each cell of the table, there is a number from 1 to 2n. We want to change the numbers in some of the cells and replace them with other numbers from 1 to 2n such that in ...
1
vote
1
answer
62
views
Why backtracking is giving wrong results in case of 1st question and correct results for 2nd. Leetcode #322 #78 respectively
You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money.
Return the fewest number of coins that you need to make ...
1
vote
2
answers
129
views
Dynamic programming partition array to find minimum difference fails for negative numbers
I am trying to solve the problem it works for positive integer arrays but fails for negative test cases. How to handle the below test case?
You are given an integer array nums of 2 * n integers. You ...
0
votes
0
answers
9
views
why this code is giving error in solve_spo function but not in other function use . the solve_spo function is derived from the solve_tabu function
int solve_tabu(int N ,int arr[],int t){
vector<vector<int>> dp(t+1,vector<int>(N+1,0));
for(int i=0;i<=N;i++){
dp[0][i]=1;
}
for(...
0
votes
0
answers
11
views
DynamicProgramming Proble,
Problem Link :https://www.geeksforgeeks.org/problems/count-numbers-containing-43022/1
Problem Description : You are given a number n, Return the count of total numbers from 1 to n containing 4 as a ...
-2
votes
1
answer
115
views
Coin Change: for loop analysis
I am trying to comprehend the problem which has different wording but I figured it is similar to coin change problem
Question:
Two friends are playing a game with a book numbered from 1 to 9. The game ...
-2
votes
2
answers
60
views
How to find the optimal products with the lowest price amount with the highest quantity?
I tried to write a function for myself but it somehow incorrectly outputs the final result:
function findOptimalProducts(products, budget) {
const getPrice = (priceString) => parseFloat(...
-4
votes
1
answer
64
views
Why is my code giving wrong answer when using 2d ArrayList and passing when using 2d arrays?
Here is the DP question,
Given a ‘N’ * ’M’ maze with obstacles, count and return the number of unique paths to reach the right-bottom cell from the top-left cell. A cell in the given maze has a value '...
3
votes
1
answer
67
views
Return correct value at each iteration- dynamic programming
The problem goes like this:
Geek is going for n day training program. He can perform any one of these three activities Running, Fighting, and Learning Practice. Each activity has some point on each ...
0
votes
1
answer
21
views
TLE on coin combinations 1 cses
can someone tell why the following code for coin combinations 1 question from cses problemset is getting time limit exceeded
#include <bits/stdc++.h>
#define int long long
using namespace std;
...
1
vote
0
answers
44
views
The principle of solving a problem through dynamic programming
I have the following task, but I don’t understand how I could solve it through dynamic programming or perhaps I need to solve it through graphs, could someone help me solve it?
The frog Sandy likes ...
0
votes
0
answers
33
views
How can longest strictly increasing subarray problem have overlapping subproblems
In the longest strictly increasing subarray problem, we have an array A, and we need to find the longest subarray such that in that subarray S, S[k]>S[k-1].
Since we can divide the array A into ...
0
votes
1
answer
51
views
Visiting dynamic website and clicking on arrows to expand and then select elements to load the page contents using Python
I am nope in python. I want python to visit this site https://icd.who.int/browse10/2019/en , and click on (arrows to expand them) which are located on this
//tr[@class='ygtvrow']//td[starts-with(@id, '...
0
votes
0
answers
71
views
How to implement join order optimization using dynamic programming in Python?
I am working on a project to optimize SQL queries by determining the optimal join order using dynamic programming in Python.
Context
I am connecting to a PostgreSQL database and need to calculate the ...