-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Bronze II] Title: 블랙잭, Time: 80 ms, Memory: 31120 KB -BaekjoonHub
- Loading branch information
1 parent
98639f5
commit cd250f1
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# [Bronze II] 블랙잭 - 2798 | ||
|
||
[문제 링크](https://www.acmicpc.net/problem/2798) | ||
|
||
### 성능 요약 | ||
|
||
메모리: 31120 KB, 시간: 80 ms | ||
|
||
### 분류 | ||
|
||
브루트포스 알고리즘 | ||
|
||
### 제출 일자 | ||
|
||
2024년 5월 14일 15:29:07 | ||
|
||
### 문제 설명 | ||
|
||
<p>카지노에서 제일 인기 있는 게임 블랙잭의 규칙은 상당히 쉽다. 카드의 합이 21을 넘지 않는 한도 내에서, 카드의 합을 최대한 크게 만드는 게임이다. 블랙잭은 카지노마다 다양한 규정이 있다.</p> | ||
|
||
<p>한국 최고의 블랙잭 고수 김정인은 새로운 블랙잭 규칙을 만들어 상근, 창영이와 게임하려고 한다.</p> | ||
|
||
<p>김정인 버전의 블랙잭에서 각 카드에는 양의 정수가 쓰여 있다. 그 다음, 딜러는 N장의 카드를 모두 숫자가 보이도록 바닥에 놓는다. 그런 후에 딜러는 숫자 M을 크게 외친다.</p> | ||
|
||
<p>이제 플레이어는 제한된 시간 안에 N장의 카드 중에서 3장의 카드를 골라야 한다. 블랙잭 변형 게임이기 때문에, 플레이어가 고른 카드의 합은 M을 넘지 않으면서 M과 최대한 가깝게 만들어야 한다.</p> | ||
|
||
<p>N장의 카드에 써져 있는 숫자가 주어졌을 때, M을 넘지 않으면서 M에 최대한 가까운 카드 3장의 합을 구해 출력하시오.</p> | ||
|
||
### 입력 | ||
|
||
<p>첫째 줄에 카드의 개수 N(3 ≤ N ≤ 100)과 M(10 ≤ M ≤ 300,000)이 주어진다. 둘째 줄에는 카드에 쓰여 있는 수가 주어지며, 이 값은 100,000을 넘지 않는 양의 정수이다.</p> | ||
|
||
<p>합이 M을 넘지 않는 카드 3장을 찾을 수 있는 경우만 입력으로 주어진다.</p> | ||
|
||
### 출력 | ||
|
||
<p>첫째 줄에 M을 넘지 않으면서 M에 최대한 가까운 카드 3장의 합을 출력한다.</p> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
""" | ||
[문제 이해] | ||
- 카드 합 21 이내, 합 최대 | ||
- (N)C(3) -> M을 넘지않으면서 최대값 | ||
- 이때의 카드 3장의 합 | ||
""" | ||
|
||
import sys | ||
from itertools import combinations | ||
|
||
def cinput(): | ||
return sys.stdin.readline().rstrip() | ||
|
||
N, M = map(int, cinput().split()) | ||
arr = map(int, cinput().split()) | ||
|
||
sum_max = 0 | ||
|
||
# 추후 필요 시 내장 함수 구현하기 | ||
for cards in combinations(arr, 3): | ||
sum_temp = sum(cards) | ||
|
||
if sum_temp <= M and sum_temp > sum_max: | ||
sum_max = sum_temp | ||
|
||
print(sum_max) |