0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

「AtCoder Beginner Contest 254B - Practical Computing」メモ

Posted at

これは個人的備忘録です。

問題

AtCoder Beginner Contest 254

考察

ans = [[0]*i for i in range(1,n+1)]

これによってサイズiで初期値が0の配列をn+1回重ねて二次元配列をつくることによって回答に使う二次元配列を生成できる。このとき0のサイズをnにしないように注意する。

for a in ans:
    print(*a)

で答えの出力ができる
$ans_{ij}$は$i=0$のとき$j$は存在しないがそれは最初の条件分岐でカバーできる。

ACコード

n=int(input())

ans = [[0]*i for i in range(1,n+1)]

for i in range(n):
    for j in range(i+1):
        if j == 0 or j == i:
            ans[i][j] = 1
        else:
            ans[i][j] = ans[i-1][j-1] + ans[i-1][j]

for a in ans:
    print(*a)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?