- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures

- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces

# C++ Program to check k rupees are enough to reach final cell or not

Suppose we have three numbers n, m and k. There is a n x m grid. we are currently at cell (0,0) top left corner and we want to reach cell (n - 1, m - 1). We can move to the neighboring cells to the right or down. To reach down, it will take x rupees, and to reach right cell, it will take y rupees. We have to check whether we can reach cell (n - 1, m - 1) spending exactly k rupees or not. (The x and y are the current x and y coordinate of the cell + 1)

## Problem Category

The given problem is an example of a divide-and-conquer problem that we can solve using Dynamic programming. Dynamic programming is a type of divide-and-conquer technique where a particular problem is divided into subproblems and then solved. There is a difference between the normal divide-and-conquer technique and dynamic programming, that is the latter solves the overlapping subproblems and uses that result whenever it is needed again. To store the result of these overlapping subproblems, the dynamic programming technique uses a table, and this process is called 'memoization'. The data from the table is examined each time a subproblem has to be solved. Typically, dynamic programming techniques are used for optimization problems where an optimal value of a solution has to be found. Examples of this programming technique include Fibonacci series problems, Bellman-Ford single-source shortest path problem, matrix chain multiplication problem, longest common subsequence problem, etc.

https://www.tutorialspoint.com/data_structures_algorithms/dynamic_programming.htm

So, if the input of our problem is like n = 2; m = 2; k = 3, then the output will be True.

## Steps

To solve this, we will follow these steps −

if k is same as n * m - 1, then: return true Otherwise return false

## Example

Let us see the following implementation to get better understanding −

#include <bits/stdc++.h> using namespace std; bool solve(int n, int m, int k){ if (k == n * m - 1) return true; else return false; } int main(){ int n = 2; int m = 2; int k = 3; cout << solve(n, m, k) << endl; }

## Input

2, 2, 3

## Output

1

- Related Articles
- Program to check person can reach top-left or bottomright cell avoiding fire or not in Python
- Program to check robot can reach target position or not in Python
- Check if the given number K is enough to reach the end of an array in Python
- Program to check we can reach leftmost or rightmost position or not in Python
- C++ program to check the coins forms x amount of rupees or not
- Program to check if array pairs are divisible by k or not using Python
- C++ code to check grasshopper can reach target or not
- Program to find minimum cost to reach final index with at most k steps in python
- Program to check we can reach at position n by jumping or not in Python
- Program to find out if k monitoring stations are enough to monitor particular points in Python
- Program to check whether final string can be formed using other two strings or not in Python
- Program to check pattern of length m repeated K or more times exists or not in Python
- C Program to check if two strings are same or not
- Program to check whether parentheses are balanced or not in Python
- C++ Program to check if given numbers are coprime or not