https://school.programmers.co.kr/learn/courses/30/lessons/150368
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
def solution(users, emoticons):
discounts = [10, 20, 30, 40]
global max_sub, max_sale
max_sub = 0 # 최대 서비스 가입자 수
max_sale = 0 # 최대 이모티콘 판매액
# 모든 이모티콘 할인 조합 생성
def dfs(depth, combo):
global max_sub, max_sale
if depth == len(emoticons): # 끝까지 채웠을 경우(이모티콘 길이만큼)
sub_count = 0 # 서비스 가입자 수
sales = 0 # 이모티콘 판매액
for rate, limit in users: # rate: 할인율, limit: 서비스가입기준
total = 0 # user의 이모티콘 총 구매액
for i, price in enumerate(emoticons):
if combo[i] >= rate: # 할인율이 기준에 맞을 때만 구매
total += price * (100 - combo[i]) // 100
if total >= limit: # user의 이모티콘 총 구매액이 기준을 넘으면
sub_count += 1 # 서비스 가입
else:
sales += total # 이모티콘 판매액 추가
# 현재 조합이 가장 나은지 확인
if sub_count > max_sub or (sub_count == max_sub and sales > max_sale):
max_sub = sub_count
max_sale = sales
return
# 이모티콘마다 할인율을 선택하여 dfs 호출
for discount in discounts:
dfs(depth + 1, combo + [discount])
dfs(0, [])
return [max_sub, max_sale]
'프로그래머스' 카테고리의 다른 글
프로그래머스 43105. 정수 삼각형 (0) | 2024.12.21 |
---|---|
프로그래머스 150369. 택배 배달과 수거하기 (0) | 2024.11.26 |
프로그래머스 42839. 소수 찾기 (0) | 2024.11.19 |
프로그래머스 42842. 카펫 (0) | 2024.11.17 |
프로그래머스 42840. 모의고사 (0) | 2024.11.16 |