#P3010. [USACO11JAN] Dividing the Gold S

[USACO11JAN] Dividing the Gold S

题目描述

Bessie and Canmuu found a sack of N (1 <= N <= 250) gold coins that they wish to divide as evenly as possible. Coin i has value v_i (1 <= V_i <= 2,000). The cows would like to split the pile as evenly as they can, but that is not always possible. What is the smallest difference between the values of the two piles?

In addition, the Bessie and Canmuu have found that there might be multiple ways to split the piles with that minimum difference. They would also like to know the number of ways to split the coins as fairly as possible. If it isn't possible to split the piles evenly, Bessie will get the higher-valued pile.

By way of example, consider a sack of five coins of values: 2, 1, 8, 4, and 16. Bessie and Canmuu split the coins into two piles, one pile with one coin worth 16, and the other pile with the remaining coins worth 1+2+4+8=15. Therefore the difference is 16-15 = 1. This is the only way for them to split the coins this way, so the number of ways to split it evenly is just 1.

Note that same-valued coins can be switched among the piles to increase the number of ways to perform an optimal split. Thus, the set of coins {1, 1, 1, 1} has six different ways to split into two optimal partitions, each with two coins.

贝茜和Canmuu发现一麻袋的N(1 <= N的<= 250)金币 他们希望尽可能平均划分。我是有价的硬币 v_i(1 <= V_i <= 2,000)。奶牛想分裂桩作为 因为它们可以均匀,但这是不可能的。什么是 之间的差异最小两堆的价值? 此外,贝茜和Canmuu发现,有可能 分裂与多种方式,最低的区别桩。他们 还想知道如何分裂硬币为数字 公正地反映了可能。如果它是不可能分裂桩均匀,贝西 将获得价值较高的桩。

输入格式

* Line 1: A single integer: N

* Lines 2..N+1: Line i+1 contains a single integer: V_i

输出格式

* Line 1: A single integer that is the smallest difference of two partitions.

* Line 2: A single integer that is the number of ways to split the coins with the minimum difference printed in line 1. Since this number can get quite large, print the remainder when divided by 1,000,000.

5 
2 
1 
8 
4 
16 
1 
1