Created
April 26, 2020 07:31
-
-
Save niklasjang/4986754941f7b5245e5ba8ba4e58213c to your computer and use it in GitHub Desktop.
[PS][기출문제][삼성]/[BOJ][14889][스타트와 링크]
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
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
#include <string.h> | |
#include <queue> | |
using namespace std; | |
int n = 0; | |
int map[20][20]; | |
int pointSum = 0; | |
int arr[20]; | |
int ans = 0xFFFFFF; | |
bool visited[20]; | |
int main(void) { | |
cin.tie(NULL); | |
ios::sync_with_stdio("false"); | |
cin >> n; | |
int i = 0, j = 0; | |
for (i = 0; i < n; i++) { | |
if (i >= n / 2) arr[i] = 1; | |
for (int j = 0; j < n; j++) { | |
cin >> map[i][j]; | |
pointSum += map[i][j]; | |
} | |
} | |
do{ | |
int a = 0, b = 0; | |
for (i = 0; i < n; i++) { | |
for (j = i + 1; j < n; j++) { | |
if (arr[i] != arr[j]) continue; | |
if (arr[i] == 0) { | |
a += map[i][j]; | |
a += map[j][i]; | |
} | |
else { | |
b += map[i][j]; | |
b += map[j][i]; | |
} | |
} | |
} | |
ans = min(ans, abs(a - b)); | |
} while (next_permutation(arr, arr + n)); | |
cout << ans << "\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
///recur 풀이