최대 1 분 소요

사용 언어: Python3

문제

스크린샷 2023-05-04 오후 12 18 38

풀이

내 풀이

from itertools import combinations

N, K = map(int, input().split())
lst = list(map(int, input().split()))
M = int(input())

cnt = 0
for x in combinations(lst, K):
    if sum(x) % M == 0:
        cnt += 1
print(cnt)
  • 정답!
  • 테스트 환경에서 라이브러리를 사용하지 못하게 막을 수 있기 때문에 DFS를 이용한 풀이를 꼭 알아두자.


💛 개인 공부 기록용 블로그입니다. 👻

맨 위로 이동하기