Balanced Cow Subsets
Time limit1sMemory limit128 MB
Count how many subsets of up to 20 cows can be split into two groups with equal total milk output.
- Level
Hard8 of 10
- Topics
- Backtracking, Bit manipulation, Hash map, Divide and conquer
- Solved
- No attempts yet
Problem
Farmer John owns cows (), where cow produces units of milk each day ().
John installs a new milking machine in his barn, but it only works when the cows on the left side of the barn have exactly the same total milk output as the cows on the right side.
Call a subset of cows balanced if it can be partitioned into two groups having equal total milk output. Determine how many of the subsets of the cows are balanced.
Input
The first line contains the integer .
Each of the next lines contains one integer; line contains .
Output
Print, on a single line, the number of balanced subsets of cows.