Cost of painting n * m grid | C ++ implementation of the approach ; Function to return the minimum cost ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int getMinCost ( int n , int m ) { int cost = ( n - 1 ) * m + ( m - 1 ) * n ; return cost ; } int main ( ) { int n = 4 , m = 5 ; cout << getMinCost ( n , m ) ; return 0 ; }