hgk0404.tistory
Code After Work
hgk0404.tistory

공지사항

전체 방문자
오늘
어제
  • 전체 카테고리
    • [컴퓨터비전]
    • [Computer Science]
      • [컴퓨터네트워크]
      • [알고리즘]
      • [자료구조 in C]
      • [C & C++]
      • [이산수학]
      • [Math]
    • [머신러닝]
      • [Numpy, Pandas]
    • [Cloud]
      • [AWS]
      • [NCP]
      • [Kubernetes]
      • [Terraform]
    • [Dev]
      • [가상환경]
      • [Linux]
      • [Docker]
    • [Python]
    • [Coding Test]
      • [백준]
      • [프로그래머스]
      • [SQL]
    • [WEB]
    • [일상]
    • [엑셀]
    • [금융]

인기 글

최근 글

최근 댓글

250x250
hELLO · Designed By 정상우.
hgk0404.tistory

Code After Work

[백준] 2798: 블랙잭
[Coding Test]/[백준]

[백준] 2798: 블랙잭

2022. 6. 24. 20:34
728x90

2798번 : 블랙잭 

import sys
from itertools import combinations
def solution(n, m, cards):
    total = 0
    for card in combinations(cards, 3):
        if sum(card) <= m:
            total = max(sum(card), total)
    return total
n, m = map(int, sys.stdin.readline().split())
cards = list(map(int, sys.stdin.readline().split()))
print(solution(n, m, cards))

모든 경우를 탐색해야해서 완전탐색 문제인데, 그 중 3개만을 더해야 하는 문제입니다. 그런데 5 6 7과 7 6 5는 순서는 다르지만 같은 것으로 인식하기 때문에 순서를 고려하지 않는 조합을 사용해야 하는 문제입니다. itertools, combinations를 사용해서 문제를 풀었습니다.

부분수열의 합

728x90
저작자표시 동일조건 (새창열림)

'[Coding Test] > [백준]' 카테고리의 다른 글

[백준] 2178: 미로 탐색  (0) 2022.06.27
[백준] 7568: 덩치  (0) 2022.06.24
[백준] 2231: 분해합  (0) 2022.06.24
[백준] 1018: 체스판 다시 칠하기  (0) 2022.06.24
[백준] 2869 python(파이썬) : 달팽이는 올라가고 싶다 - 상세해설  (0) 2022.05.20
'[Coding Test]/[백준]' 카테고리의 다른 글
  • [백준] 2178: 미로 탐색
  • [백준] 7568: 덩치
  • [백준] 2231: 분해합
  • [백준] 1018: 체스판 다시 칠하기
hgk0404.tistory
hgk0404.tistory
공부기록

티스토리툴바