์ƒˆ์†Œ์‹

๐Ÿงฎ PS

๋ฐฑ์ค€ (boj) ํŒŒ์ด์ฌ - 2775 ๋ถ€๋…€ํšŒ์žฅ์ด ๋ ํ…Œ์•ผ

  • -

๋ฌธ์ œ ๋งํฌ : https://www.acmicpc.net/problem/2775

 

2775๋ฒˆ: ๋ถ€๋…€ํšŒ์žฅ์ด ๋ ํ…Œ์•ผ

์ฒซ ๋ฒˆ์งธ ์ค„์— Test case์˜ ์ˆ˜ T๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๊ฐ๊ฐ์˜ ์ผ€์ด์Šค๋งˆ๋‹ค ์ž…๋ ฅ์œผ๋กœ ์ฒซ ๋ฒˆ์งธ ์ค„์— ์ •์ˆ˜ k, ๋‘ ๋ฒˆ์งธ ์ค„์— ์ •์ˆ˜ n์ด ์ฃผ์–ด์ง„๋‹ค. (1 <= k <= 14, 1 <= n <= 14)

www.acmicpc.net

 

 

๊ทธ๋ƒฅ 2์ฐจ์› ๋ฐฐ์—ด์„ ๋งŒ๋“ค์–ด์„œ, array[์ธต][ํ˜ธ์‹ค] ์ด๋ผ๋Š” ์ธ๋ฑ์Šค๋กœ ๊ตฌํ˜„์„ํ•ด์„œ ํ’€์—ˆ๋‹ค. ๋‹ค๋ฅธ์‚ฌ๋žŒ์˜ ํ’€์ด๋ณด๋‹ค ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์“ธ๋ฐ์—†์ด ๋งŽ์ด ์“ด๊ฒƒ๊ฐ™๊ธด ํ•˜์ง€๋งŒ ๋ฌธ์ œ์—์„œ์˜ ์ž…๋ ฅ๋ฒ”์œ„๊ฐ€ ํฌ์ง€ ์•Š์•„ ๊ดœ์ฐฎ์„๊ฑฐ๋ผ๊ณ  ์ƒ๊ฐํ–ˆ๋‹ค.

t = int(input())


for i in range(t):
    k = int(input())
    n = int(input())
    arr=[[0 for i in range(n)]for i in range(k+1)]

    for q in range(n): #0์ธต์˜ ์ธ์›์ˆ˜ ์ฑ„์šฐ๊ธฐ.
        arr[0][q] = q+1 

    for j in range(1,k+1): #0์ธต์˜ ์ธ์›์ˆ˜๋ฅผ ๋”ํ•ด 1์ธต...2์ธต.... ์Œ“์•„๊ฐ€๋Š” ๋ฐ˜๋ณต๋ฌธ
        for z in range(n):
            arr[j][z] += sum(arr[j-1][:z+1])

    print(arr[k][n-1])
Contents

ํฌ์ŠคํŒ… ์ฃผ์†Œ๋ฅผ ๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค

์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๊ณต๊ฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.