- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# 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

#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 Questions & Answers
- Program to find minimum cost for painting houses in Python
- Sum of even numbers from n to m regardless if n<m or n>m JavaScript
- Count of numbers satisfying m + sum(m) + sum(sum(m)) = N in C++
- Construct DPDA for anbmc(n+m) n,m≥1 in TOC
- Construct PDA for L = {0n1m2(n+m) | m,n >=1}
- Find a positive number M such that gcd(N^M,N&M) is maximum in Python
- Construct Pushdown automata for L = {0n1m2(n+m) | m,n = 0} in C++
- Construct DPDA for a(n+m)bmcn n,m≥1 in TOC
- Print first m multiples of n in C#
- Construct Pushdown automata for L = {0(n+m)1m2n | m, n = 0} in C++
- Construct Pushdown automata for L = {0m1(n+m)2n | m,n = 0} in C++
- Calculate n + nn + nnn + ? + n(m times) in Python
- Calculate the value of (m)1/n in JavaScript
- Construct Turing machine for L = {an bm a(n+m) - n,m≥1} in C++
- Connect n ropes with minimum cost

Advertisements