Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 1차원 DP
- 2차원 dp
- 99클럽
- @BeforeAll
- @BeforeEach
- @Builder
- @Entity
- @GeneratedValue
- @GenericGenerator
- @NoargsConstructor
- @Query
- @Table
- @Transactional
- Actions
- Amazon EFS
- amazon fsx
- Android Studio
- ANSI SQL
- api gateway 설계
- api gateway 필터
- ApplicationEvent
- assertThat
- async/await
- AVG
- AWS
- aws eks
- AWS KMS
- aws 연동
- AWS 프리티어
- Azure
Archives
- Today
- Total
기록
백준_15661_링크와 스타트 본문
문제
https://www.acmicpc.net/problem/15661
15661번: 링크와 스타트
첫째 줄에 N(4 ≤ N ≤ 20)이 주어진다. 둘째 줄부터 N개의 줄에 S가 주어진다. 각 줄은 N개의 수로 이루어져 있고, i번 줄의 j번째 수는 Sij 이다. Sii는 항상 0이고, 나머지 Sij는 1보다 크거나 같고, 100
www.acmicpc.net
풀이
1. make team
팀1이 가질수 있는 선수들의 경우의 수를 구한다.
선수의 수를 n//2로 둔 이유는 중복을 제거하기 위해서이다. (아래 두 경우를 같게 취급)
team1 | team1 | team1 | team2 | team1 | team1 | team2 |
team2 | team2 | team2 | team1 | team2 | team2 | team1 |
2. calculation diff ability
두팀의 능력값을 계산해 차이를 구한다.
코드
import sys
from itertools import combinations
input = sys.stdin.readline
N = int(input().strip())
board = [list(map(int, input().strip().split())) for i in range(N)]
# 2. calculation diff ability
def getAbility(selection) :
ability = 0
for i in range(N) :
for j in range(i, N) :
it = board[i][j]+board[j][i]
isTeam1 = selection[i]==True and selection[j]==True
isTeam2 = selection[i]==False and selection[j]==False
ability += it*isTeam1 - it*isTeam2
return abs(ability)
# 1. make team
ans = float('INF')
for np in range(N//2) :
combi = list(combinations(range(N), np+1))
for playerList in combi :
selection = [False, ]*N
for player in playerList :
selection[player] = True
ans = min(ans, getAbility(selection))
print(ans)
'코딩테스트 > python' 카테고리의 다른 글
백준_16946_벽 부수고 이동하기4 (0) | 2022.10.03 |
---|---|
백준_14391_종이조각 (0) | 2022.05.10 |
백준_10830_행렬 제곱 (0) | 2022.05.03 |
백준_2961_도영이가 만든 맛있는 음식 (0) | 2022.04.22 |
백준_1022_소용돌이 예쁘게 출력하기 (0) | 2022.04.19 |