https://www.acmicpc.net/problem/9095
9095번: 1, 2, 3 더하기
각 테스트 케이스마다, n을 1, 2, 3의 합으로 나타내는 방법의 수를 출력한다.
www.acmicpc.net
문제
1,2,3 의 합으로 n을 만드는 방법의 수
풀이
기본 dfs로 풀이
import sys
input = sys.stdin.readline
def dfs(s):
global answer
if s == n:
answer += 1
if s >= n:
return
for i in range(1,4):
dfs(s+i)
T = int(input())
for t in range(T):
n = int(input())
answer = 0
dfs(0)
print(answer)
'코딩테스트 > 백준' 카테고리의 다른 글
[Python] boj 14499 주사위 굴리기 (0) | 2022.11.23 |
---|---|
[python] BOJ 14500 테트로미노 (0) | 2022.10.28 |
[Python/그리디] BOJ 11399 - ATM (0) | 2022.04.13 |
[Python/그리디] BOJ 1931 (0) | 2022.04.13 |
[Python] BOJ 1541 - 잃어버린 괄호 (0) | 2022.04.13 |
댓글