| gaelim |
... ̽ µ.
켱 ĽĮ ﰢ̸ õ ڳ
ϴ
# Construct a 2D ragged list a of integers. The list must have n + 1 rows,
# with the ith (0 <= i <= n) row a[i] having i + 1 elements, each initialized
# to 1. For example, if n = 3, a should be initialized to
# [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]].
κп, n +1 ŭ, n+1ŭ 2D array ϴµ 1 ʱȭ϶.
̽㿡 ϴ° ߸,
ϴ ̰ 2 for ҰŰ
for i=0 to i<=n
for j=0 to j<=i
a.push(1)
̷ ϸ
[[1], [1,1], [1,1,1], [1,1,1,1] ] ̷ ðŰ
ĽĮ ﰢ δ
1
1 1
1 2 1
1 3 3 1
̷ ݾƿ
ٵ 迭 (̽㿡 Ʈ?) ٸ
1
1 1
1 2 1
1 3 3 1
̷ ǿ ǵϴ°ó
1
1 1
1 1* 1
1 1 1 1
⼭ ϴµ
1* κ ش i(row,) 2, j(column,) 1̿
a[2][1] = a[1][0]+a[1][1] Ǵ°ſ
ٵ ۼں ۼϽŰ ϱ
# Fill the ragged list a using the formula for Pascal's triangle
# a[i][j] = a[i - 1][j - 1] + a[i - 1][j]
# where 0 <= i <= n and 1 <= j < i.
for i in range(0, n):
for j in range(1, i):
a[i][j] = a[i - 1][j - 1] + a[i-1][j]
̷ ִµ ּ 0<=i<=n, 1<=j<i Ʈ ִµ
ۼϽŰźϱ for ȣϳ (0, n) (1, i) εȣ Ѱ ߸ȰŰ? ̺κ ݵ Ͻñ
ּκп
# Write out the ragged list a, with elements separated by spaces, and each
# row ending in a newline.
Ǿִµ
϶°Ű
ϴ ϽǶ¿ ̷ ϸǿ CóغԿ
for (int i=0; i<=n; i++){
for (int j=i; j<n; j++){
printf(" ");
}
for (int j=0; j<=i; j++){
printf("%d ", a[i]); // "%d " <-- ̽ Ѱ ϼ ^^;;
}
printf("\n");
}
̷ ϸ ڰ ڳ ^^;; |
2017/10/15 |
|