
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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 x 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
Advertisements