| 12
 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
 
 | class Solution {
 int[] arr = new int[]{9090400, 8499400, 5926800,
 8547000, 4958200, 4422600, 5751200, 4175600, 6309600,
 5865200, 6604400, 4635000, 10663400, 8087200, 4554000};
 int ans = 0x3f3f3f3f;
 
 public int dfs(int x,int y,int sub){
 
 if(x + y == 15){
 ans = Math.min(ans,Math.abs(sub));
 
 return 0;
 }
 
 int now = sub;
 dfs(x + 1,y,now + arr[x + y]);
 dfs(x,y + 1,now - arr[x + y]);
 return 0;
 }
 
 public void dfs2(int u,int s1,int s2){
 if(u == arr.length){
 ans = Math.min(ans,Math.abs(s1 - s2));
 return;
 }
 dfs2(u + 1,s1 + arr[u],s2);
 dfs2(u + 1,s1,s2 + arr[u]);
 }
 
 public void solve(){
 
 dfs(0,0,0);
 
 System.out.println(ans);
 }
 }
 
 |