Codeforces Round 171 (Div. 2)
D
The Minimum Number of Variables
Codeforces
2200
原题
← CE →
翻译中…

You've got a positive integer sequence $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$. All numbers in the sequence are distinct. Let's fix the set of variables $*b*_{1}, *b*_{2}, ..., *b*_{*m*}$. Initially each variable $*b*_{*i*}$ $(1 ≤ *i* ≤ *m*)$ contains the value of zero. Consider the following sequence, consisting of $*n*$ operations.

翻译中…

The first operation is assigning the value of $*a*_{1}$ to some variable $*b*_{*x*}$ $(1 ≤ *x* ≤ *m*)$. Each of the following $*n* - 1$ operations is assigning to some variable $*b*_{*y*}$ the value that is equal to the sum of values that are stored in the variables $*b*_{*i*}$ and $*b*_{*j*}$ $(1 ≤ *i*, *j*, *y* ≤ *m*)$. At that, the value that is assigned on the $*t*$-th operation, must equal $*a*_{*t*}$. For each operation numbers $*y*, *i*, *j*$ are chosen anew.

翻译中…

Your task is to find the minimum number of variables $*m*$, such that those variables can help you perform the described sequence of operations.

翻译中…

Input

翻译中…

The first line contains integer $*n*$ $(1 ≤ *n* ≤ 23)$. The second line contains $*n*$ space-separated integers $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$ $(1 ≤ *a*_{*k*} ≤ 10^{9})$.

翻译中…

It is guaranteed that all numbers in the sequence are distinct.

翻译中…

Output

翻译中…

In a single line print a single number — the minimum number of variables $*m*$, such that those variables can help you perform the described sequence of operations.

翻译中…

If you cannot perform the sequence of operations at any $*m*$, print -1.

翻译中…

Note

翻译中…

In the first sample, you can use two variables $*b*_{1}$ and $*b*_{2}$ to perform the following sequence of operations.

翻译中…
  1. $*b*_{1}$ := $1$;
  2. $*b*_{2}$ := $*b*_{1} + *b*_{1}$;
  3. $*b*_{1}$ := $*b*_{1} + *b*_{2}$;
  4. $*b*_{1}$ := $*b*_{1} + *b*_{1}$;
  5. $*b*_{1}$ := $*b*_{1} + *b*_{2}$.
翻译中…

样例

Input #1
5
1 2 3 6 8
Output #1
2
InputCopy OutputCopy
Input #2
3
3 6 5
Output #2
-1
InputCopy OutputCopy
Input #3
6
2 4 8 6 10 18
Output #3
3
InputCopy OutputCopy
题目信息
题号
279D
时间限制
1 s
内存限制
256 MB
标签
位运算
动态规划

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。