Skip to content

Commit 449c0a7

Browse files
committed
1020
1 parent b83f3de commit 449c0a7

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

.idea/modules.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

BOJ/gold/BOJ15661/BOJ15661.iml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>

BOJ/gold/BOJ15661/src/Main.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.Arrays;
5+
import java.util.StringTokenizer;
6+
7+
public class Main {
8+
static int N;
9+
static int [][] table;
10+
static int Minv =Integer.MAX_VALUE;
11+
public static void main(String[] args) throws IOException {
12+
13+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
14+
StringTokenizer st;
15+
N= Integer.parseInt(br.readLine());
16+
table = new int[N][N];
17+
for (int i = 0; i < N; i++) {
18+
st= new StringTokenizer(br.readLine());
19+
int j=0;
20+
while (st.hasMoreTokens()){
21+
table[i][j]=Integer.parseInt(st.nextToken());
22+
j++;
23+
}
24+
}
25+
int [] team =new int [N];
26+
FindTeam(team,0,0);
27+
System.out.println(Minv);
28+
}
29+
30+
private static void FindTeam(int[] team, int idx, int r) {
31+
if(r>0 && r<N){
32+
FindDiff(team);
33+
}
34+
35+
36+
for (int i = idx; i < N; i++) {
37+
team[i]=1;
38+
FindTeam(team,i+1 ,r+1);
39+
team[i]=0;
40+
}
41+
42+
43+
}
44+
45+
private static void FindDiff(int[] team) {
46+
int teamA=0;
47+
int teamB=0;
48+
for (int i = 0; i < team.length; i++) {
49+
for (int j = i+1; j < team.length; j++) {
50+
if(team[i]==1 && team[j]==1){
51+
teamA+=(table[i][j]+table[j][i]);
52+
} else if (team[i]==0&&team[j]==0) {
53+
teamB+=(table[i][j]+table[j][i]);
54+
55+
}
56+
}
57+
}
58+
int cac= Math.abs(teamA-teamB);
59+
Minv=Math.min(Minv,cac);
60+
}
61+
}

0 commit comments

Comments
 (0)