-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14889.cpp
More file actions
51 lines (44 loc) · 935 Bytes
/
Copy path14889.cpp
File metadata and controls
51 lines (44 loc) · 935 Bytes
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
int n, answer=987987987, tmp, myTrue=0, myFalse=0;
int map[22][22];
bool visited[22];
void getSum(){
myTrue =0;
myFalse=0;
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
if(!visited[i] and !visited[j]) myTrue += map[i][j];
if(visited[i] and visited[j]) myFalse += map[i][j];
}
}
}
void dfs(int x, int cnt){
if(cnt>=n/2){
getSum();
tmp = myTrue - myFalse;
if(tmp<0) tmp = -tmp;
answer = min(answer,tmp);
return;
}
for(int i=x+1; i<=n; i++){
visited[i]=true;
dfs(i, cnt+1);
visited[i]=false;
}
}
int main() {
//Please Enter Your Code Here
scanf("%d", &n);
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
scanf("%d", &map[i][j]);
}
}
visited[1]=true;
dfs(1, 1);
printf("%d", answer);
return 0;
}