TLE in Tiling Problem

I am getting TLE in my code, kindly tell what changes should be done in my code. Here 's it :

@Puneet_Sharma
recursion will give TLE in this question you have to optimize your code.

Read the problem as a matrix of size M x N, rather than N x M as it helps in easy visualization.
In this manner,

A tile can be either place vertically,meaning it will only occupy a cell of width 1 and a complete hieght of M. Or,
You can place M tiles horizontally one over the other if there is enough width left.