Skip to content

Commit fe6c89e

Browse files
committed
DP - II : Started!
1 parent 07ef203 commit fe6c89e

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package dynamicProgramming2;
2+
3+
/*
4+
Min Cost Path Problem
5+
6+
An integer matrix of size (M x N) has been given. Find out the minimum cost to reach from the cell (0, 0) to (M - 1, N - 1).
7+
From a cell (i, j), you can move in three directions:
8+
1. ((i + 1), j) which is, "down"
9+
2. (i, (j + 1)) which is, "to the right"
10+
3. ((i+1), (j+1)) which is, "to the diagonal"
11+
The cost of a path is defined as the sum of each cell's values through which the route passes.
12+
Input format :
13+
The first line of the test case contains two integer values, 'M' and 'N', separated by a single space. They represent the 'rows' and 'columns' respectively, for the two-dimensional array/list.
14+
15+
The second line onwards, the next 'M' lines or rows represent the ith row values.
16+
17+
Each of the ith row constitutes 'N' column values separated by a single space.
18+
Output format :
19+
Print the minimum cost to reach the destination.
20+
Constraints :
21+
1 <= M <= 10 ^ 2
22+
1 <= N <= 10 ^ 2
23+
24+
Time Limit: 1 sec
25+
Sample Input 1 :
26+
3 4
27+
3 4 1 2
28+
2 1 8 9
29+
4 7 8 1
30+
Sample Output 1 :
31+
13
32+
Sample Input 2 :
33+
3 4
34+
10 6 9 0
35+
-23 8 9 90
36+
-200 0 89 200
37+
Sample Output 2 :
38+
76
39+
Sample Input 3 :
40+
5 6
41+
9 6 0 12 90 1
42+
2 7 8 5 78 6
43+
1 6 0 5 10 -4
44+
9 6 2 -10 7 4
45+
10 -2 0 5 5 7
46+
Sample Output 3 :
47+
18
48+
* */
49+
public class MinimumCostPath {
50+
public static void main(String[] args) {
51+
52+
}
53+
}

0 commit comments

Comments
 (0)