All Questions
Tagged with dynamic-programming matrix
121
questions
2
votes
4
answers
101
views
Is there a way initialize a matrix(2D array) with some default values(-1)
I was going through a dp problem, there I have to initialize the matrix with default(-1) values for memoized solution. And felt the need.
We can initialize the 1D array in java like this => Arrays....
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 ...
0
votes
2
answers
150
views
How to traverse in 2D matrix not row or column wise but diagonally filling all the coordinates
I was trying to solve a dp question and got struck here during tabulation as through normal method this matrix will be filled row wise or column wise, but I needed values diagonally, instead of row ...
0
votes
1
answer
195
views
sum max path of matrix using dynamic programming
Given a matrix mat[][], of dimensions N * N, I need to find the path from the top-left cell (0, 0) to the bottom-right cell (N – 1, N – 1) of the given matrix such that sum of the elements in the path ...
0
votes
0
answers
64
views
Dynamic programming: find all submatrix with highest cell number
I have N*M matrix, for example
1 2 3
4 5 6
7 8 9
I want to find all submatrixes by index, in which this index is the biggest.
For example: cell 1 has only submatrix 1, because it is the highest ...
0
votes
2
answers
100
views
Is there a way to implement in Julia an array of matrices with fixed dimension of the array but not of the matrices?
I wanted to create an array of matrices.
I know the size of the array has to be M because I have M matrices; I know those matrices have 2 columns each.
The problem is that I'm trying to start with ...
-1
votes
1
answer
69
views
Adding memorization (dp) to my recursive code gives different result which is wrong
I have been stuck on this LeetCode problem Number of increasing paths in a grid:
You are given an m x n integer matrix grid, where you can move from a cell to any adjacent cell in all 4 directions.
...
0
votes
0
answers
36
views
I was trying to solve this question on GFG. Can anyone please tell me what is wrong with my code?
Geek's Journey
You're provided with two arrays:
"geeksTown" of length n - representing the heights of buildings in
Geek's town "journey" of length m - representing the ...
1
vote
0
answers
23
views
How to acces dynamic allocated through class object?
i am working on a task where i need to acces a dynamically allocated memory to create a matrix.
If i did it correct, i reserved some memory for the size of my matrix and at the setze_element object of ...
-1
votes
1
answer
147
views
Dynamic Programming Implementation- Maximal Square 0's and 1's variant
Given a matrix of 0's and 1's. Find a maximal square where the corner position in a square can either be a zero or one but all other positions must have one. Return the left upper position and right ...
1
vote
1
answer
71
views
Cant initialize a 2d array/matrix to 0 [duplicate]
I am trying to initialize a 2d array (matrix) to 0 but, cant do it:
int longestCommonSubsequence(string text1, string text2) {
int len1=0;
len1=text1.length()+1;
int len2=0;
len2=text2....
1
vote
2
answers
324
views
Top down approach 01 Matrix
I new do dynamic programming and I am attempting the following problem on leetcode: 01 Matrix
Problem: Given an m x n binary matrix mat, return the distance of the nearest 0 for each cell. The ...
0
votes
2
answers
38
views
How to select 2 elements from a list such that it represents the size of a matrix? [duplicate]
I was solving the matrix chain problem and I've encountered a dead end.
I have the values of p0,p1,p2,p3,p4,p5 as 4,10,3,12,20,7 respectively
now I want to mark that p0 and p1 combine together to form ...
0
votes
0
answers
69
views
Python find the maximum total score from a matrix
I have a 6 * 14 matrix, each element of the matrix represents a score; my goal is to find the maximum total score as well as which element was picked from each row.
Only 1 element can be selected for ...
2
votes
0
answers
50
views
Maximal sidelength of a square containing a point and intersecting no other square
Given a list of squares L, each embedded (non-overlapping) in an n x n grid, I would like to find the sidelength of the largest square (not in L) which contains an given position (i,j) and does not ...