#P3067. [USACO12OPEN] Balanced Cow Subsets G

[USACO12OPEN] Balanced Cow Subsets G

题目描述

Farmer John's owns N cows (2 <= N <= 20), where cow i produces M(i) units of milk each day (1 <= M(i) <= 100,000,000). FJ wants to streamline the process of milking his cows every day, so he installs a brand new milking machine in his barn. Unfortunately, the machine turns out to be far too sensitive: it only works properly if the cows on the left side of the barn have the exact same total milk output as the cows on the right side of the barn!

Let us call a subset of cows "balanced" if it can be partitioned into two groups having equal milk output. Since only a balanced subset of cows can make the milking machine work, FJ wonders how many subsets of his N cows are balanced. Please help him compute this quantity.

输入格式

* Line 1: The integer N.

* Lines 2..1+N: Line i+1 contains M(i).

输出格式

* Line 1: The number of balanced subsets of cows.

题目大意

我们定义一个奶牛集合 SS 是平衡的,当且仅当满足以下两个条件:

  • SS 非空。
  • SS 可以被划分成两个集合 A,BA,B,满足 AA 里的奶牛产奶量之和等于 BB 里的奶牛产奶量之和。划分的含义是,AB=SA\cup B=SAB=A\cap B=\varnothing

现在给定大小为 nn 的奶牛集合 SS,询问它有多少个子集是平衡的。请注意,奶牛之间是互不相同的,但是它们的产奶量可能出现相同。

输入格式

第一行一个整数 nn,表示奶牛的数目。

22n+1n+1 行,每行一个数 aia_i,表示每头奶牛的产奶量。

输出格式

输出一个数表示方案总数。

样例解释

共存在三种方案。集合 {1,2,3}\{1,2,3\} 可以划分为 {1,2}\{1,2\}{3}\{3\};集合 {1,3,4}\{1,3,4\} 可以划分为 {1,3}\{1,3\}{4}\{4\};集合 {1,2,3,4}\{1,2,3,4\} 可以划分为 {1,4}\{1,4\}{2,3}\{2,3\},共 33 种子集。

数据范围及约定

对于全部数据,保证 1n201\le n\le 201ai1081\le a_i\le 10^8

4 
1 
2 
3 
4 

3 

提示

There are 4 cows, with milk outputs 1, 2, 3, and 4.

There are three balanced subsets: the subset {1,2,3}, which can be partitioned into {1,2} and {3}, the subset {1,3,4}, which can be partitioned into {1,3} and {4}, and the subset {1,2,3,4} which can be partitioned into {1,4} and {2,3}.