Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Input:
N = 3, M = 3, K = 2
Volcano = {{2, 1},
           {2, 3}}
Output: 
2
Explanation: 
at time = 0, only cell (2, 1) and (2, 3) 
are filled with lava
at time = 1, cell (1, 1), (2, 1), (3, 1), 
(2, 2), (1, 3), (2, 3), (3, 3) are filled 
with lava
at time = 2, all cells are filled with lava


What I have tried:

// { Driver Code Starts
//Initial Template for C++

#include <bits/stdc++.h>
using namespace std;


 // } Driver Code Ends
//User function Template for C++


class Solution {
public:
    int solve(int N, int M, int K, vector<vector<int> > Volcano) {
        // code here
  int dp[R][C]=;
    int m = R, n = C;
 
    // Base case
    dp[m - 1][n - 1] = points[m - 1][n - 1] > 0
                           ? 1
                           : abs(points[m - 1][n - 1]) + 1;
 
    // Fill last row and last column as base to fill
    // entire table
    for (int i = m - 2; i >= 0; i--)
        dp[i][n - 1]
            = max(dp[i + 1][n - 1] - points[i][n - 1], 1);
    for (int j = n - 2; j >= 0; j--)
        dp[m - 1][j]
            = max(dp[m - 1][j + 1] - points[m - 1][j], 1);
 
    // fill the table in bottom-up fashion
    for (int i = m - 2; i >= 0; i--) {
        for (int j = n - 2; j >= 0; j--) {
            int min_points_on_exit
                = min(dp[i + 1][j], dp[i][j + 1]);
            dp[i][j]
                = max(min_points_on_exit - points[i][j], 1);
        }
    }
 
    return Volcano[0][0]=dp[0][0];
    }
};
Posted
Comments
Richard MacCutchan 18-Sep-22 4:19am    
You need to provide more details of exactly what the code is supposed to do, and what problem you are having.
OriginalGriff 18-Sep-22 4:39am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with - we get no other context for your project.
Imagine this: you go for a drive in the country, but you have a problem with the car. You call the garage, say "it broke" and turn off your phone. How long will you be waiting before the garage arrives with the right bits and tools to fix the car given they don't know what make or model it is, who you are, what happened when it all went wrong, or even where you are?

That's what you've done here. So stop typing as little as possible and try explaining things to people who have no way to access your project!

Use the "Improve question" widget to edit your question and provide better information.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900