We will find a way, we always have.

-interstellar

Problem Solving/๋ฐฑ์ค€

[๋ฐฑ์ค€] 2775๋ฒˆ: ๋ถ€๋…€ํšŒ์žฅ์ด ๋ ํ…Œ์•ผ - ํŒŒ์ด์ฌ

Redddy 2022. 6. 2. 23:00

๐Ÿงฉ๋ฌธ์ œ ํ•ด์„

a์ธต์˜ bํ˜ธ์— ์‚ด๋ ค๋ฉด ์ž์‹ ์˜ ์•„๋ž˜(a-1)์ธต์˜ 1ํ˜ธ๋ถ€ํ„ฐ bํ˜ธ๊นŒ์ง€ ์‚ฌ๋žŒ๋“ค์˜ ์ˆ˜์˜ ํ•ฉ๋งŒํผ ์‚ฌ๋žŒ๋“ค์„ ๋ฐ๋ ค์™€ ์‚ด์•„์•ผํ•œ๋‹ค.
k์™€ n์ด ์ฃผ์–ด์งˆ๋•Œ k์ธต์˜ nํ˜ธ์—๋Š” ๋ช‡ ๋ช…์ด ์‚ด๊ณ  ์žˆ๋Š”์ง€ ์ถœ๋ ฅํ•˜๋ฉด ๋œ๋‹ค.

์ธต์€ 0์ธต๋ถ€ํ„ฐ ์žˆ์ง€๋งŒ ์ž…๋ ฅ ๋ฒ”์œ„๋Š” 1 <= k,n <= 14 ์ด๋‹ค. ์ฆ‰ 0์ธต์€ ์ฃผ์–ด์ง€์ง€ ์•Š๋Š”๋‹ค.

 

๐Ÿ“• ํ’€์ด

์œ„๋กœ ์˜ฌ๋ผ๊ฐˆ์ˆ˜๋ก ๋”ํ•˜๊ธฐ๋งŒ ์ฃผ๊ตฌ์žฅ์ฐฝ ํ•ด์ฃผ๋ฉด ๋œ๋‹คใ…Ž

์ด์ œ ๊ฐ ์ธต์— ๋ช‡๋ช…์ด ์‚ด๊ณ  ์žˆ๋Š”์ง€ ํ‘œ๋กœ ์‚ดํŽด๋ณด์ž.

 

2์ธต 1 4 (1+3) 10 (1+3+6) ์•„๋ž˜์ธต ์ „๋ถ€ ๋”ํ•œ ๊ฐ’
1์ธต 1 3 (1+2) 6 (1+2+3) n๊นŒ์ง€์˜ ํ•ฉ
0์ธต 1 2 3 n
  1ํ˜ธ 2ํ˜ธ 3ํ˜ธ nํ˜ธ

 

์ด๋•Œ n์ธต์˜ kํ˜ธ์˜ ๋ช‡ ๋ช…์ด ์‚ฌ๋Š”์ง€ ๊ตฌํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ๋‘๊ฐ€์ง€ ์ •๋„๊ฐ€ ์žˆ๋‹ค.

๋ฌธ์ œ์—์„œ ์ฃผ์–ด์ง„ ๊ฒƒ์ฒ˜๋Ÿผ ์ž์‹ ์˜ ์•„๋ž˜ ์ธต์˜ 1ํ˜ธ๋ถ€ํ„ฐ nํ˜ธ๊นŒ์ง€์˜ ํ•ฉ์„ ๊ตฌํ•  ์ˆ˜๋„ ์žˆ๊ณ , ์•„๋‹ˆ๋ฉด ์ž์‹ ์˜ ์ธต์˜ (n-1)ํ˜ธ์— ์ž์‹ ์˜ ์•„๋ž˜์ธต nํ˜ธ๋ฅผ ๋”ํ•˜์—ฌ ๊ตฌํ•  ์ˆ˜๋„ ์žˆ๋‹ค. 

์™€๋”ฐ์‹œ๋Š” ์ „์ž๋กœ ๋‹ต์„ ๊ตฌํ–ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ํ›„์ž๋Š” ๊ธ€์„ ์ž‘์„ฑํ•˜๋‹ค ๋ณด๋‹ˆ ๋– ์˜ฌ๋ž๋‹คใ…Žใ…Ž

 

๐Ÿ’ป ์ฝ”๋“œ

import sys
input = sys.stdin.readline

for t in range(int(input())): # ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค
    k= int(input().rstrip()) # ์ธต ์ž…๋ ฅ๋ฐ›์Œ
    n = int(input().rstrip()) # ํ˜ธ ์ž…๋ ฅ๋ฐ›์Œ
    arr = [num for num in range(1, n+1)] # 0์ธต์— ์‚ฌ๋Š” ์นœ๊ตฌ
    for i in range(k):
        new = [] # ๊ฐ’ ๋‹ด์•„์ค„ ์ž„์‹œ ์ €์žฅ์†Œ
        for j in range(n):
            new.append(sum(arr[:j+1])) # nํ˜ธ๊นŒ์ง€์˜ ํ•ฉ์„ ๋”ํ•˜์—ฌ new์— ์ถ”๊ฐ€
        arr= new.copy() # arr๋กœ ๋ฐ˜ํ™˜ํ•ด์คŒ ์œ„ ๊ณผ์ •์„ k์ธต๊นŒ์ง€ ๋ฐ˜๋ณต
    print(arr[-1]) # k์ธต์˜ nํ˜ธ ๊ฐ’ ์ถœ๋ ฅ

 

๐Ÿ”— ๋ฌธ์ œ ๋งํฌ : ๋ถ€๋…€ํšŒ์žฅ์ด ๋ ํ…Œ์•ผ

 

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

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

www.acmicpc.net

 

python