Hint
I assume that all triangles are of the form:
---
-
And not like:
- or - or -
--- -- --
- -
Remark that a 2-units triangles is made up of three 1-unit triangles. A 3-unit triangles is made up of 3 overlapping 2-unit triangles, and so on.
The next figure is an example of a 3-unit triangles made up of three 2-units triangles, themselves made up of three 1-unit triangles
- -+ -+* +* * --- +++ ***
- + * ==> - + *
o o
Spoiler: full algorithm follow, don't read it
/!\ spoiler alert /!\
/!\ spoiler alert /!\
/!\ spoiler alert /!\
The main algorithm
You can do a first pass to compute all unit sized triangles (having exactly 1 - inside). Maintain a table where T[x,y] is the size of the triangle (length of its sides). In this pass you initialize every cell with a - to 1.
Then you can go from top to bottom and try to build more complex triangles.
When at position [x,y], you should consider the triangles whose down head is at:
- [x-1,y-1]
- [x ,y-1]
- [x+1,y-1]
The size of the new triangles will be 1 plus the minimum size of any of the 3 above triangles. Then you update the table T[x,y]
T[x,y+1] = 1 + min(T[x-1,y], T[x,y], T[x+1,y])
At the end, just find the biggest sized triangles in your table T and compute the corresponding triangle area. (formula left as an exercise to the reader)
Complexity is O(n²).