#P2315. [HNOI2005] 数三角形
[HNOI2005] 数三角形
Description

Xiao Su sees an equilateral triangle: each side of the equilateral triangle has length and is divided into equal parts, so each side has division points. The whole triangle is divided into unit equilateral triangles (with side length ) by segments that connect division points on two different sides and are parallel to the third side. The figure on the left below shows the case :

Xiao Su wants to know, after deleting some of the short edges, how many triangles are formed by the remaining edges (including all triangles with side length (), counting both upright and inverted ones). A triangle is counted if all its short edges have not been deleted. For example, in the figure on the right above, there are triangles.
Input Format

All short edges of the large triangle can be regarded as the boundaries of unit triangles, as shown by the gray triangles in the figure below. There is gray triangle in the st row, gray triangles in the nd row, …, and gray triangles in the th row. Therefore, the input format is specified as follows:

The first line contains a positive integer (), which is the side length of the large triangle.
The next lines: on the -th line there are groups of numbers. From left to right, each group describes one triangle. Each group contains numbers, each either or , indicating whether the corresponding short edge is deleted. means deleted, means not deleted. The three numbers describe, in order, the left, right, and bottom edges of the triangle. Therefore, the -th line contains numbers, each being or .
Output Format
Output a single integer , the number of triangles whose boundaries have not been deleted.
5
1 1 1
1 1 0 1 1 0
1 1 1 1 1 1 1 0 1
1 0 1 1 1 1 0 1 1 1 1 1
0 1 1 1 1 1 0 1 1 1 1 1 0 1 1
19
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号