现在的位置: 首页 > 综合 > 正文

Hdu 3765 Celebrity Split

2018年04月23日 ⁄ 综合 ⁄ 共 2546字 ⁄ 字号 评论关闭

Hdu 3765 
Celebrity Split

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)


Total Submission(s): 18    Accepted Submission(s): 16

Problem Description

Jack and Jill have decided to separate and divide their property equally. Each of their N mansions has a value between 1,000,000 and 40,000,000 dollars. Jack will receive some of the mansions; Jill will receive some of the mansions; the remaining mansions will be sold, and the proceeds split equally.




Neither Jack nor Jill can tolerate the other receiving property with higher total value. The sum of the values of the mansions Jack receives must be equal to the sum of the values of the mansions Jill receives. So long as the value that each receives is equal, Jack and Jill would like each to receive property of the highest possible value.




Given the values of N mansions, compute the value of the mansions that must be sold so that the rest may be divided so as to satisfy Jack and Jill.

Input

The input consists of a sequence of test cases. The first line of each test case contains a single integer N, the number of mansions, which will be no more than 20. This line is followed by N lines, each giving the value of a mansion. The final line of input contains the integer zero. This line is not a test case and should not be processed.

Output

For each test case, output a line containing a single integer, the value of the mansions that must be sold so that the rest may be divided so as to satisfy Jack and Jill.

Sample Input

6000000 30000000 3000000 11000000 3000000 0

Sample Output

41000000

 

题目大意:Jack

Jill
要平分
N<=20
栋房子,每栋房子有自己的价格,他们两个人得到的房子价格之和必须相等,而不一定
20
栋房子能够被两个人平分,所以如果两个人平分后剩下没有被分到的房子要拿去拍卖,而他们希望拿去拍卖的房子价格最少,问最少的价格是多少。

这个题目一看很像背包题,我似乎感觉在以前做过很多这种类型的背包题,两个人分一堆东西什么的,但是仔细想想,貌似问的问题一般是“问能否平分”“假设A
拿的不少于
B
的,相对最公平的分发是神马……”呃……可能是俺孤陋寡闻了(这题如果哪位大神会背包的解法求教……)

N=20的时候其实如果枚举是可以解决的。

对于一个物品,要么给Jack
,要么给
Jill
,要么拍卖,所以可以递归求解。



其实递归是很好用的……


【上篇】
【下篇】

抱歉!评论已关闭.