알고리즘/완전탐색
[백준][Python] 16439번 치킨치킨치킨
임짠짠
2022. 7. 22. 15:27
반응형
16439번: 치킨치킨치킨
첫 번째 줄에 고리 회원의 수 N (1 ≤ N ≤ 30) 과 치킨 종류의 수 M (3 ≤ M ≤ 30) 이 주어집니다. 두 번째 줄부터 N개의 줄에 각 회원의 치킨 선호도가 주어집니다. i+1번째 줄에는 i번째 회원의 선
www.acmicpc.net
코드
from itertools import combinations
import sys
n,m = map(int,input().split())
a_list = []
max_t = 0
for _ in range(n):
a_list.append(list(map(int,sys.stdin.readline().split())))
comb = list(combinations(range(m),3))
for a,b,c in comb:
total = 0
for i in range(n):
total += max(a_list[i][a],a_list[i][b],a_list[i][c])
max_t = max(max_t,total)
print(max_t)
설명
combinations를 사용해서 0부터 m까지 중에서 3개를 고를 수 있는 모든 경우의 수를 구했다.
각 조합을 골랐을 때 만족도의 합을 구해서 그 중 최댓값을 출력하게 해줬다.
반응형