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 |
| 31 |
Tags
- 건강
- SWEA
- BOJ
- priorityqueue
- 시뮬레이션
- DP
- greedy
- 프로그래머스
- 투포인터
- 문제해결
- COS PRO
- binary search
- 러닝일지
- dfs
- 코테
- 문자열
- 백준
- oracle
- 알고리즘
- BFS
- 문제풀이
- 운동기록
- 자바
- SQL
- db
- 코딩테스트
- MySQL
- Java
- math
- 이분탐색
Archives
- Today
- Total
슈콩
[BOJ] 14889 스타트와 링크 본문


[문제]
https://www.acmicpc.net/problem/14889
[소스 코드]
import java.io.*;
import java.util.*;
public class Main {
static int n,result;
static boolean[] visit;
static int[][] team;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
n = Integer.parseInt(br.readLine());
team = new int[n][n];
for(int i=0;i<n;i++) {
st = new StringTokenizer(br.readLine());
for(int j=0;j<n;j++) {
team[i][j] = Integer.parseInt(st.nextToken());
}
}
visit = new boolean[n];
result = Integer.MAX_VALUE;
dfs(0,0);
System.out.println(result);
}
private static void dfs(int cnt,int idx) {
if(cnt==n/2) {
int link = 0;
int start = 0;
for(int i=0;i<n;i++) {
if(visit[i]) {
for(int j=0;j<n;j++) {
if(i!=j && visit[j]) {
link += team[i][j];
}
}
}
else {
for(int j=0;j<n;j++) {
if(i!=j && !visit[j]) {
start += team[i][j];
}
}
}
}
result = Math.min(result, Math.abs(link - start));
return;
}
for(int i=idx;i<n;i++) {
if(!visit[i]) {
visit[i] = true;
dfs(cnt+1,i+1);
visit[i] = false;
}
}
}
}'Algorithms > Baekjoon' 카테고리의 다른 글
| [BOJ] 14891 톱니바퀴 (0) | 2025.12.01 |
|---|---|
| [BOJ] 14890 경사로 (0) | 2025.12.01 |
| [BOJ] 14888 연산자 끼워넣기 (0) | 2025.12.01 |
| [BOJ] 14502 연구소 (0) | 2025.12.01 |
| [BOJ] 14501 퇴사 (0) | 2025.12.01 |