In each row, the first and last element are 1. And the other element is the sum of the two elements in the previous row.
This problem can be solved by iterating through each row and calculating each element in the row as the sum of the corresponding elements in the previous row.
The given code snippet demonstrates the solution in C++.