Given M x N Chessboard. The task is to determine the Maximum numbers of cuts that we can make in the Chessboard such that the Chessboard is not divided into 2 parts.

**Examples:**

Input:M = 2, N = 4Output:Maximum cuts = 3Input:M = 3, N = 3Output:Maximum cuts = 4

**Representation:**

- For M = 2, N = 2 We can only make 1 cut (mark in red). if we make 1 more cut then the chessboard will divide into 2 pieces.
- For M = 2, N = 4 We can makes 3 cuts (marks in red). if we make 1 more cut then the chessboard will divide into 2 pieces.

So, it can be observed that no. of cuts = **(m-1) * (n-1)**.

Below is the implementation of the above approach:

## C++

`// C++ implementation of above approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// function that calculates the ` `// maximum no. of cuts ` `int` `numberOfCuts(` `int` `M, ` `int` `N) ` `{ ` ` ` `int` `result = 0; ` ` ` ` ` `result = (M - 1) * (N - 1); ` ` ` ` ` `return` `result; ` `} ` ` ` `// Driver Code ` `int` `main() ` `{ ` ` ` `int` `M = 4, N = 4; ` ` ` ` ` `// Calling function. ` ` ` `int` `Cuts = numberOfCuts(M, N); ` ` ` ` ` `cout << ` `"Maximum cuts = "` `<< Cuts; ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of above approach ` ` ` `class` `GFG { ` ` ` `// function that calculates the ` `// maximum no. of cuts ` `static` `int` `numberOfCuts(` `int` `M, ` `int` `N) ` `{ ` ` ` `int` `result = ` `0` `; ` ` ` ` ` `result = (M - ` `1` `) * (N - ` `1` `); ` ` ` ` ` `return` `result; ` `} ` ` ` `// Driver Code ` `public` `static` `void` `main(String args[]) ` `{ ` ` ` `int` `M = ` `4` `, N = ` `4` `; ` ` ` ` ` `// Calling function. ` ` ` `int` `Cuts = numberOfCuts(M, N); ` ` ` ` ` `System.out.println(` `"Maximum cuts = "` `+ Cuts); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation of ` `# above approach ` ` ` `# function that calculates the ` `# maximum no. of cuts ` `def` `numberOfCuts(M, N): ` ` ` `result ` `=` `0` ` ` ` ` `result ` `=` `(M ` `-` `1` `) ` `*` `(N ` `-` `1` `) ` ` ` ` ` `return` `result ` ` ` `# Driver code ` `if` `__name__` `=` `=` `'__main__'` `: ` ` ` ` ` `M, N ` `=` `4` `, ` `4` ` ` ` ` `# Calling function. ` ` ` `Cuts ` `=` `numberOfCuts(M, N) ` ` ` ` ` `print` `(` `"Maximum cuts = "` `, Cuts) ` ` ` `# This code is contributed by ` `# Kriti_mangal ` |

*chevron_right*

*filter_none*

## C#

`//C# implementation of above approach ` `using` `System; ` ` ` `public` `class` `GFG{ ` `// function that calculates the ` `// maximum no. of cuts ` `static` `int` `numberOfCuts(` `int` `M, ` `int` `N) ` `{ ` ` ` `int` `result = 0; ` ` ` ` ` `result = (M - 1) * (N - 1); ` ` ` ` ` `return` `result; ` `} ` ` ` `// Driver Code ` ` ` ` ` `static` `public` `void` `Main (){ ` ` ` ` ` `int` `M = 4, N = 4; ` ` ` `// Calling function. ` ` ` `int` `Cuts = numberOfCuts(M, N); ` ` ` ` ` `Console.WriteLine(` `"Maximum cuts = "` `+ Cuts); ` ` ` `} ` `//This code is contributed by akt_mit ` `} ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// php implementation of above approach ` ` ` `// function that calculates the ` `// maximum no. of cuts ` `function` `numberOfCuts(` `$M` `, ` `$N` `) ` `{ ` ` ` `$result` `= 0; ` ` ` ` ` `$result` `= (` `$M` `- 1) * (` `$N` `- 1); ` ` ` ` ` `return` `$result` `; ` `} ` ` ` `// Driver Code ` `$M` `= 4; ` `$N` `= 4; ` ` ` `// Calling function. ` `$Cuts` `= numberOfCuts(` `$M` `, ` `$N` `); ` ` ` `echo` `"Maximum cuts = "` `, ` `$Cuts` `; ` ` ` `// This code is contributed by ANKITRAI1 ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

Maximum cuts = 9

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Minimum cuts required to divide the Circle into equal parts
- Check if any square (with one colored cell) can be divided into two equal parts
- Check if an array of 1s and 2s can be divided into 2 parts with equal sum
- Number of ways N can be divided into four parts to construct a rectangle
- Possible cuts of a number such that maximum parts are divisible by 3
- Split a number into 3 parts such that none of the parts is divisible by 3
- Divide N into K unique parts such that gcd of those parts is maximum
- Check if array can be divided into two sub-arrays such that their absolute difference is K
- Number of K's such that the given array can be divided into two sets satisfying the given conditions
- Split the number into N parts such that difference between the smallest and the largest part is minimum
- Count positions in a chessboard that can be visited by the Queen which are not visited by the King
- Minimize number of cuts required to break N length stick into N unit length sticks
- First N natural can be divided into two sets with given difference and co-prime sums
- Find the sums for which an array can be divided into sub-arrays of equal sum
- Check if N can be divided into K consecutive elements with a sum equal to N
- Check if a given array can be divided into pairs with even sum
- Check if a line at 45 degree can divide the plane into two equal weight parts
- Divide a number into two parts such that sum of digits is maximum
- Partition N into M parts such that difference between Max and Min part is smallest
- Find the number of ways to divide number into four parts such that a = c and b = d

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.