Problem 79
Pascal's Triangle Row
Easy · 10 pts · Math, Dynamic Programming
Problem
Pascal's triangle starts with row 0, which is just 1. Each later row begins and ends with 1, and every inner value is the sum of the two values directly above it. The first rows are 1, then 1 1, then 1 2 1, then 1 3 3 1. Given K, print row K, which has K + 1 values. The values in row K are the binomial coefficients C(K, 0), C(K, 1), ..., C(K, K). For K up to 60 they fit in a 64-bit integer. You can build the rows one by one, or compute each value from the previous one with C(K, i) = C(K, i - 1) × (K - i + 1) / i.
Input
A single integer K.
Output
Print the K + 1 values of row K, space-separated.
Constraints
0 <= K <= 60
Example input
4
Example output
1 4 6 4 1
Explanation
Row 3 is 1 3 3 1. Row 4 starts and ends with 1, and its inner values are 1 + 3 = 4, 3 + 3 = 6 and 3 + 1 = 4. So row 4 is 1 4 6 4 1.