From 4698b931bb471f09409dadaadb9a7686ad638716 Mon Sep 17 00:00:00 2001 From: Sanjay Majhi <47259000+sanjaymajhi@users.noreply.github.com> Date: Sat, 3 Oct 2020 11:56:03 +0530 Subject: [PATCH] Create MinCostPath.cpp Given a cost matrix cost[][] and a position (m, n) in cost[][], write a function that returns cost of minimum cost path to reach (m, n) from (0, 0). Each cell of the matrix represents a cost to traverse through that cell. Total cost of a path to reach (m, n) is sum of all the costs on that path (including both source and destination). You can only traverse down, right and diagonally lower cells from a given cell, i.e., from a given cell (i, j), cells (i+1, j), (i, j+1) and (i+1, j+1) can be traversed. You may assume that all costs are positive integers. --- .../Dynamic Programming/C++/MinCostPath.cpp | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Algorithms/Dynamic Programming/C++/MinCostPath.cpp diff --git a/Algorithms/Dynamic Programming/C++/MinCostPath.cpp b/Algorithms/Dynamic Programming/C++/MinCostPath.cpp new file mode 100644 index 0000000..e768d5c --- /dev/null +++ b/Algorithms/Dynamic Programming/C++/MinCostPath.cpp @@ -0,0 +1,39 @@ +#include +#define endl "\n" +using namespace std; + +const int row = 3; +const int col = 3; + +int minCost(int cost[row][col]) { + + // for 1st column + for (int i=1 ; i