Given a floor of size** MxN** size and tiles of size** 2×1**, the task is to find the maximum number of tiles required to cover the floor as much as possible of size **MxN** size.**Note: **A tile can either be placed horizontally or vertically and no two tiles should overlap.

**Examples:**

Input:M = 2, N = 4Output:4Explanation:

4 tiles are needed to cover the floor.

Input:M = 3, N = 3Output:4Explanation:

4 tiles are needed to cover the floor.

**Approach:**

- If
**N**is**even**, then the task is to place m rows of**(N/2)**number of tiles to cover the whole floor. - Else if
**N**is**odd**, then cover**M**rows till**N – 1**(even) columns in the same way as discussed in the above point and put**(M/2)**number of tiles in the last column. If both**M and N are odd**, then one cell of the floor remains uncovered. - Therefore, the maximum number of tiles is
**floor((M * N) / 2)**.

Below is the implementation of the above approach:

## C++

`// C++ program for the above approach` `#include <bits/stdc++.h>` `using` `namespace` `std;` `// Function to find the maximum number` `// of tiles required to cover the floor` `// of size m x n using 2 x 1 size tiles` `void` `maximumTiles(` `int` `n, ` `int` `m)` `{` ` ` `// Print the answer` ` ` `cout << (m * n) / 2 << endl;` `}` `// Driver Code` `int` `main()` `{` ` ` `// Given M and N` ` ` `int` `M = 3;` ` ` `int` `N = 4;` ` ` `// Function Call` ` ` `maximumTiles(N, M);` ` ` `return` `0;` `}` |

*chevron_right*

*filter_none*

## Java

`// Java program for the above approach ` `import` `java.util.*;` `class` `GFG{` `// Function to find the maximum number` `// of tiles required to cover the floor` `// of size m x n using 2 x 1 size tiles` `static` `void` `maximumTiles(` `int` `n, ` `int` `m)` `{` ` ` ` ` `// Print the answer` ` ` `System.out.println((m * n) / ` `2` `);` `}` `// Driver code` `public` `static` `void` `main (String[] args)` `{` ` ` `// Given M and N` ` ` `int` `M = ` `3` `;` ` ` `int` `N = ` `4` `;` ` ` ` ` `// Function call` ` ` `maximumTiles(N, M);` `}` `}` `// This code is contributed by offbeat` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program for the above approach ` `# Function to find the maximum number` `# of tiles required to cover the floor` `# of size m x n using 2 x 1 size tiles` `def` `maximumTiles(n, m):` ` ` `# Prthe answer` ` ` `print` `(` `int` `((m ` `*` `n) ` `/` `2` `));` `# Driver code` `if` `__name__ ` `=` `=` `'__main__'` `:` ` ` `# Given M and N` ` ` `M ` `=` `3` `;` ` ` `N ` `=` `4` `;` ` ` `# Function call` ` ` `maximumTiles(N, M);` `# This code is contributed by sapnasingh4991` |

*chevron_right*

*filter_none*

## C#

`// C# program for the above approach ` `using` `System;` `class` `GFG{` `// Function to find the maximum number` `// of tiles required to cover the floor` `// of size m x n using 2 x 1 size tiles` `static` `void` `maximumTiles(` `int` `n, ` `int` `m)` `{` ` ` ` ` `// Print the answer` ` ` `Console.WriteLine((m * n) / 2);` `}` `// Driver code` `public` `static` `void` `Main(String[] args)` `{` ` ` `// Given M and N` ` ` `int` `M = 3;` ` ` `int` `N = 4;` ` ` ` ` `// Function call` ` ` `maximumTiles(N, M);` `}` `}` `// This code is contributed by amal kumar choubey` |

*chevron_right*

*filter_none*

**Output:**

6

**Time Complexity:** O(1)**Auxiliary Space:** O(1)

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 number of square tiles required to fill the rectangular floor
- Minimum tiles of sizes in powers of two to cover whole area
- Number of squares of side length required to cover an N*M rectangle
- Minimum number of points required to cover all blocks of a 2-D grid
- Minimum time required to cover a Binary Array
- Floor value Kth root of a number using Recursive Binary Search
- Minimum cost to cover the given positions in a N*M grid
- Count number of ways to cover a distance | Set 2
- Count minimum number of fountains to be activated to cover the entire garden
- Floor square root without using sqrt() function : Recursive
- Minimum distance to travel to cover all intervals
- Minimum lines to cover all points
- Minimum steps needed to cover a sequence of points on an infinite grid
- Minimum squares to cover a rectangle
- Program to Calculate the Edge Cover of a Graph
- Sum of product of x and y such that floor(n/x) = y
- Ceil and Floor functions in C++
- JavaScript Math floor() Method
- Summation of floor of harmonic progression
- All possible values of floor(N/K) for all values of K

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.