From ce51ec2abc152655afa202df92253217dc3840b8 Mon Sep 17 00:00:00 2001 From: Seongbeom Park Date: Sun, 28 Apr 2024 02:44:42 +0900 Subject: [PATCH] =?UTF-8?q?solve=203xn=20=ED=83=80=EC=9D=BC=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + 3xn타일링/README.md | 35 +++++++++++++++++++++++++++++++++++ 3xn타일링/solution.py | 10 ++++++++++ 3xn타일링/test.py | 13 +++++++++++++ run.py | 16 ++++++++++------ 5 files changed, 69 insertions(+), 6 deletions(-) create mode 100644 .gitignore create mode 100644 3xn타일링/README.md create mode 100644 3xn타일링/solution.py create mode 100644 3xn타일링/test.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eeb8a6e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +**/__pycache__ diff --git a/3xn타일링/README.md b/3xn타일링/README.md new file mode 100644 index 0000000..c359219 --- /dev/null +++ b/3xn타일링/README.md @@ -0,0 +1,35 @@ +# [3xn 타일링](https://school.programmers.co.kr/learn/courses/30/lessons/12902) + +## 문제 설명 +가로 길이가 2이고 세로의 길이가 1인 직사각형 모양의 타일이 있습니다. 이 직사각형 타일을 이용하여 세로의 길이가 3이고 가로의 길이가 n인 바닥을 가득 채우려고 합니다. 타일을 채울 때는 다음과 같이 2가지 방법이 있습니다 + +타일을 가로로 배치 하는 경우 +타일을 세로로 배치 하는 경우 +예를들어서 n이 8인 직사각형은 다음과 같이 채울 수 있습니다. + +Imgur + +직사각형의 가로의 길이 n이 매개변수로 주어질 때, 이 직사각형을 채우는 방법의 수를 return 하는 solution 함수를 완성해주세요. + +## 제한사항 +가로의 길이 n은 5,000이하의 자연수 입니다. +경우의 수가 많아 질 수 있으므로, 경우의 수를 1,000,000,007으로 나눈 나머지를 return해주세요. + +## 입출력 예 +n result +4 11 + +## 입출력 예 설명 +### 입출력 예 #1 +다음과 같이 11가지 방법이 있다. +Imgur +Imgur +Imgur +Imgur +Imgur +Imgur +Imgur +Imgur +Imgur +Imgur +Imgur diff --git a/3xn타일링/solution.py b/3xn타일링/solution.py new file mode 100644 index 0000000..7d6a50e --- /dev/null +++ b/3xn타일링/solution.py @@ -0,0 +1,10 @@ +memo = {0: 0, 2: 3} +def solution(n): + if n in memo: + return memo[n] + if n % 2 == 1: + return 0 + + answer = sum([solution(i*2) * 2 for i in range((n-2)//2)] + [solution(n-2) * 3] + [2]) + memo[n] = answer + return answer % 1000000007 diff --git a/3xn타일링/test.py b/3xn타일링/test.py new file mode 100644 index 0000000..194e1c7 --- /dev/null +++ b/3xn타일링/test.py @@ -0,0 +1,13 @@ +from solution import solution + +test_cases = { + (0,): 0, + (1,): 0, + (2,): 3, + (3,): 0, + (4,): 11, + (6,): 3*3*3 + 3*2*2 + 2, +} + +for i, o in test_cases.items(): + print('input', *i, '\toutput', o, '\tsolution', solution(*i)) diff --git a/run.py b/run.py index 97e6257..e75ecae 100644 --- a/run.py +++ b/run.py @@ -2,17 +2,21 @@ import argparse import sys import os +import importlib problems = [ - '예상대진표' + '예상대진표', + '3xn타일링', ] if __name__ == '__main__': parser = argparse.ArgumentParser() - parser.add_argument('problem', - choices=problems) + parser.add_argument('--problems', type=list, + choices=problems, + default=problems[-1:]) args = parser.parse_args() - print(args.problem) + for problem in args.problems: + print(problem) - sys.path.append(os.path.join(os.getcwd(), args.problem)) - __import__(args.problem, fromlist=['test']) + sys.path.append(os.path.join(os.getcwd(), problem)) + __import__(problem, fromlist=['test'])