Cost of painting n * m grid in C++
In this tutorial, we will be discussing a program to find the cost of painting n*m grid.
For this we will be provided with two integers n and m. Our task is to calculate the minimum cost of painting a n*m grid is the cost of painting a cell is equal to the number of painted cells adjacent to it.
Example
Live Demo
#include <bits/stdc++.h>
using namespace std;
//calculating the minimum cost
int calc_cost(int n, int m){
int cost = (n - 1) * m + (m - 1) * n;
return cost;
}
int main(){
int n = 4, m = 5;
cout << calc_cost(n, m);
return 0;
}
Output
31
Related Articles
- Program to find minimum cost for painting houses in Python
- Number of Ways to Paint N × 3 Grid in C++
- A hemi-spherical dome of a building needs to be painted. If the circumference of the base of the dome is $17.6\ m$, find the cost of painting it, given the cost of painting is $Rs.\ 5$ per $100\ cm^2$.
- Number of Ways to Paint N × 3 Grid in C++ program
- A sheet is in the form of a rhombus whose diagonals are $10\ m$ and $8\ m$. Find the cost of painting both of its surface at the rate of Rs.$70\ per\ m^2$.
- A cylindrical pillar is $50\ cm$ in diameter and $3.5\ m$ in height. Find the cost of painting the curved surface of the pillar at the rate of $12.50$ per $m^2$.
- Count of numbers satisfying m + sum(m) + sum(sum(m)) = N in C++
- Area of a square wall is \( 1159929 \mathrm{~m}^{2} \). Find the side of the wall and also the cost of painting the wall at Rs.10 per $m^2$.
- Print first m multiples of n in C#
- Construct Pushdown automata for L = {0n1m2(n+m) | m,n = 0} in C++
- A rhombus sheet whose perimeter is $32\ m$ and whose one diagonal is $10\ m$ long, is painted on both sides at the rate of $Rs.\ 5\ per\ m^2$. Find the cost of painting.
- If \( a=x^{m+n} y^{l}, b=x^{n+l} y^{m} \) and \( c=x^{l+m} y^{n} \), prove that \( a^{m-n} b^{n-1} c^{l-m}=1 . \)
- If the cost of 7 m of cloth is Rs. 1470, find the cost of 5 m of cloth.
- A room is $8.5\ m$ long, $6.5\ m$ broad and $3.4\ m$ high. It has two doors, each measuring $( 1.5\ m\ by\ 1\ m)$ and two windows, each measuring$( 2\ m\ by\ 1\ m)$. Find the cost of painting four walls at $Rs.\ 160$ per $m^2$.
- A cylindrical pillar is \( 50 \mathrm{~cm} \) in diameter and \( 3.5 \mathrm{~m} \) in height. Find the cost of painting the curved surface of the pillar at the rate of RS.\( 12.50 \) per \( \mathrm{m}^{2} \).
Kickstart Your Career
Get certified by completing the course
Get Started