This is a problem that i thought up a couple of weeks ago but have been unable to make headway on, i was wondering if you guys could help

You are building stairs in a 5x5 grid, you wish the total height of the stair to be a maximum. you have stairs of height 1-5 to place in the grid (where the value is the height of the stair). However you cannot build a 5 height stair straight away! there are some basic restrictions, a height 1 stair can be built anywhere, a height 2 stair must be next to a height 1, a height 3, must be next to a height 1 AND 2, a height 4 must be next to a 1,2 AND 3 and a height 5 must be next to a height 1,2,3 AND 4.

So with the aim of making the biggest total for the grid, what is the optimum layout? Is it possible to generalise this to a n by m grid?

I'm new to this forum so please be nice :D

EDIT: by next to, i mean adjacent NOT diagonal

EDIT2: i think this is probably in the wrong forum, i mis-clicked :s should it be in a higher level discrete maths section?