Guest User

Untitled

a guest
Mar 17th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. class Main {
  4. public static void main(String[] args) throws Exception {
  5. Scanner sc = new Scanner(System.in);
  6. int n = sc.nextInt();
  7. int[][] s = new int[n][n];
  8. for (int a = 0; a < n; a++) {
  9. for (int b = 0; b < n; b++) {
  10. s[a][b] = sc.nextInt();
  11. }
  12. }
  13. int answer = 200000;
  14. for (int a = 0; a < 1 << (n); a++) {
  15. boolean[] bool = new boolean[n];
  16. int count = 0;
  17. for (int b = 0; b < n; b++) {
  18. if ((a & 1 << b) != 0) {
  19. bool[b] = true;
  20. count++;
  21. }
  22. }
  23. if (n - count == count) {
  24. int team0 = 0;
  25. int team1 = 0;
  26. for (int c = 0; c < n; c++) {
  27. for (int d = 0; d < n; d++) {
  28. if (bool[c] == bool[d]) {
  29. if (!bool[c]) {
  30. team0 += s[c][d];
  31. } else {
  32. team1 += s[c][d];
  33. }
  34. }
  35. }
  36. }
  37. answer = Math.min(answer, Math.abs(team1 - team0));
  38. }
  39. }
  40. System.out.println(answer);
  41. sc.close();
  42. }
  43. }
Add Comment
Please, Sign In to add comment