Problem Description: Elavenil has a chessboard with N rows and M columns. In one step, he can choose two cells of the chessboard which share a common edge that has not been cut yet) and cut the edge. Formally, the chessboard is split into two or more pieces if it is possible to partition its cells into two nonempty subsets Sl and S2 (S1032=0, 151+ |S2|=NM) such that there is no pair of cells cl,c2 (cles1,c26S2) which share a common edge that has not been cut. Elavenil does not want the board to split into two or more pieces. Compute the maximum number of steps he can perform while satisfying this condition.
Answers
Answered by
3
Example:
- Input: M = 2, N = 4
Output: Maximum cuts = 3
- Input: M = 3, N = 3
Output: 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).
// C++ program for the question will be as follows
#include <bits/stdc++.h>
using namespace std;
int numberOfCuts(int M, int N)
{
int result = 0;
result = (M - 1) * (N - 1);
return result;
}
int main()
{
int M = 4, N = 4;
int Cuts = numberOfCuts(M, N);
cout << "Maximum cuts = " << Cuts;
return 0;
}
Answered by
5
fbdjfhfjfjfjfjrjfjgtjkfkfgjf
Similar questions
Environmental Sciences,
3 hours ago
Social Sciences,
3 hours ago
Math,
8 months ago
Environmental Sciences,
8 months ago