Jae-Kyung Cho LLM Developers who was a Robotics engineer

Baekjoon-5557-1학년

처음 조건을 잘 생각해야 함!! 잘못하면 처음에 2배의 숫자가 들어갈 수 있다.

import sys
input = sys.stdin.readline

N = int(input())
numbers = list(map(int, input().split()))

dp = [[0] * 21 for _ in range(N-1)]
dp[0][numbers[0]] = 1

for n in range(1,N-1):
    for i in range(21):
        num = numbers[n]
        for j in [i+num, i-num]:
            if 0<=j<=20:
                dp[n][j] += dp[n-1][i]

print(dp[N-2][numbers[-1]])
Comments