Pascal's triangle
InterviewTime limit1sMemory limit512 MB
Build Pascal's triangle and sum all entries inside the equilateral sub-triangle whose top cell is row R, position C, with side length W.
- Level
Medium5 of 10
- Topics
- Array, Dynamic programming, Implementation, Simulation
- Solved
- No attempts yet
Problem
Pascal's triangle has the shape drawn below. The top cell holds 1, and every number except the two at the ends of a row is the sum of the number immediately above it on the left and the number immediately above it on the right. Both numbers at the ends of a row are 1.

Rows are numbered from the top starting at 1, and within a row the numbers are counted from the left starting at 1, so row holds numbers.
Consider the equilateral triangle whose top vertex is the -th number of row and whose side contains numbers. Add up every number on the sides of that triangle and inside it. For example, when is 3, is 1 and is 4, the shaded part of the picture above is that triangle, and the sum is .
Given , and , write a program that computes this sum.
Input
The first line contains the positive integers , and in this order, separated by single spaces. (, , , )
Output
Print on the first line the sum of the numbers on the sides of and inside the equilateral triangle whose top vertex is the -th number of row and whose side contains numbers.