ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป ๋ฌธ์ œ

 

16395๋ฒˆ: ํŒŒ์Šค์นผ์˜ ์‚ผ๊ฐํ˜•

ํŒŒ์Šค์นผ์˜ ์‚ผ๊ฐํ˜•์€ ์ดํ•ญ๊ณ„์ˆ˜๋ฅผ ์‚ผ๊ฐํ˜• ํ˜•ํƒœ๋กœ ๋ฐฐ์—ดํ•œ ๊ฒƒ์ธ๋ฐ, ๋ธ”๋ ˆ์ฆˆ ํŒŒ์Šค์นผ(1623-1662)์„ ๋”ฐ๋ผ ์ด๋ฆ„ ๋ถ™์—ฌ์กŒ๋‹ค. ๋‹จ์ˆœํ•œ ํ˜•ํƒœ๋กœ, ํŒŒ์Šค์นผ์˜ ์‚ผ๊ฐํ˜•์€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฐฉ๋ฒ•์œผ๋กœ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค. N๋ฒˆ์งธ ํ–‰

www.acmicpc.net


โœ๐Ÿป ํ’€์ด

๐ŸŽจ Go

// https://www.acmicpc.net/problem/16395
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n, k int
	fmt.Fscanln(reader, &n, &k)

	var dp = make([][]int, n)
	for i := 0; i < n; i++ {
		dp[i] = make([]int, n)
	}
	for i := 0; i < n; i++ {
		for j := 0; j < i+1; j++ {
			if j == 0 || j == i {
				dp[i][j] = 1
			} else {
				dp[i][j] = dp[i-1][j-1] + dp[i-1][j]
			}
		}
	}
	fmt.Fprintln(writer, dp[n-1][k-1])
}

๐ŸŽจ Python3

# https://www.acmicpc.net/problem/16395
import sys

if __name__ == "__main__":
    n, k = list(map(int, sys.stdin.readline().split()))
    dp = [[0]*n for _ in range(n)]
    for i in range(n):
        for j in range(i+1):
            if j == 0 or j == i:
                dp[i][j] = 1
            else:
                dp[i][j] = dp[i-1][j-1] + dp[i-1][j]
    print(dp[n-1][k-1])
728x90
๋Œ“๊ธ€