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

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

 

11727๋ฒˆ: 2×n ํƒ€์ผ๋ง 2

2×n ์ง์‚ฌ๊ฐํ˜•์„ 1×2, 2×1๊ณผ 2×2 ํƒ€์ผ๋กœ ์ฑ„์šฐ๋Š” ๋ฐฉ๋ฒ•์˜ ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์•„๋ž˜ ๊ทธ๋ฆผ์€ 2×17 ์ง์‚ฌ๊ฐํ˜•์„ ์ฑ„์šด ํ•œ๊ฐ€์ง€ ์˜ˆ์ด๋‹ค.

www.acmicpc.net


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

๐ŸŽจ Go

// https://www.acmicpc.net/problem/11727
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 count = make([]int, n+1)
	for i := 1; i < n+1; i++ {
		if i == 1 {
			count[i] = 1
		} else if i == 2 {
			count[i] = 3
		} else {
			count[i] = (count[i-1] + 2*count[i-2]) % 10007
		}
	}
	fmt.Fprintln(writer, count[n])
}

๐ŸŽจ Python3

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

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    count = [0 for i in range(n+1)]
    for i in range(1, n+1):
        if i == 1:
            count[i] = 1
        elif i == 2:
            count[i] = 3
        else:
            count[i] = (count[i-1] + 2*count[i-2]) % 10007
    print(count[n])
728x90
๋Œ“๊ธ€