ν‹°μŠ€ν† λ¦¬ λ·°

πŸ‘©πŸ»‍πŸ’» 문제

 

13699번: 점화식

λ‹€μŒμ˜ 점화식에 μ˜ν•΄ μ •μ˜λœ μˆ˜μ—΄ t(n)을 μƒκ°ν•˜μž: t(0)=1 t(n)=t(0)*t(n-1)+t(1)*t(n-2)+...+t(n-1)*t(0) 이 μ •μ˜μ— λ”°λ₯΄λ©΄, t(1)=t(0)*t(0)=1 t(2)=t(0)*t(1)+t(1)*t(0)=2 t(3)=t(0)*t(2)+t(1)*t(1)+t(2)*t(0)=5 ... 주어진 μž…λ ₯ 0 ≤ n

www.acmicpc.net


✍🏻 ν’€μ΄

🎨 Go

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

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

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

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

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

🎨 Python3

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

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    dp = [0] * (n+1)
    dp[0] = 1
    for i in range(1, n+1):
        for j in range(0, i):
            dp[i] += dp[j] * dp[i-j-1]
    print(dp[n])
728x90
λŒ“κΈ€