题目

本题总分:10 
【问题描述】
某市市长获得了若干批口罩,每一批口罩的数目如下:
(如果你把以下文 字复制到文本文件中,请务必检查复制的内容是否与文档中的一致。
在试题目 录下有一个文件 mask.txt,内容与下面的文本相同)
9090400
8499400
5926800
8547000
4958200
4422600
5751200
4175600
6309600
5865200
6604400
4635000
10663400
8087200
4554000

现在市长要把口罩分配给市内的 2 所医院。
由于物流限制,每一批口罩只 能全部分配给其中一家医院。
市长希望 2

答案

2400
package competition4;

public class Distribution2
{
public static int[] arr =
{ 9090400, 8499400, 5926800, 8547000, 4958200, 4422600, 5751200,
4175600, 6309600, 5865200, 6604400, 4635000,
10663400, 8087200, 4554000 };

public static int min=Integer.MAX_VALUE;
public static int sum=0;
public static boolean[] visited=new boolean[arr.length];

public static void main(String[] args)
{
for(int x=0;x<arr.length;x++)
{
sum +=arr[x];
}
dfs(0);
System.out.println(min);
}
public static void dfs(int index)
{
if(index>=sum/2)
{
min = Math.min(min, Math.abs(sum-index*2));
return;
}
for(int x=0;x<arr.length;x++)
{
if(!visited[x])
{
visited[x]=true;
dfs(index+arr[x]);
visited[x]=false;
}
}
}
}