CF279D.The Minimum Number of Variables

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You've got a positive integer sequence a1,a2,...,ana_{1},a_{2},...,a_{n} . All numbers in the sequence are distinct. Let's fix the set of variables b1,b2,...,bmb_{1},b_{2},...,b_{m} . Initially each variable bib_{i} (1<=i<=m)(1<=i<=m) contains the value of zero. Consider the following sequence, consisting of nn operations.

The first operation is assigning the value of a1a_{1} to some variable bxb_{x} (1<=x<=m)(1<=x<=m) . Each of the following n1n-1 operations is assigning to some variable byb_{y} the value that is equal to the sum of values that are stored in the variables bib_{i} and bjb_{j} (1<=i,j,y<=m)(1<=i,j,y<=m) . At that, the value that is assigned on the tt -th operation, must equal ata_{t} . For each operation numbers y,i,jy,i,j are chosen anew.

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

输入格式

The first line contains integer nn (1<=n<=23)(1<=n<=23) . The second line contains nn space-separated integers a1,a2,...,ana_{1},a_{2},...,a_{n} (1<=ak<=109)(1<=a_{k}<=10^{9}) .

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

输出格式

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

If you cannot perform the sequence of operations at any mm , print -1.

输入输出样例

  • 输入#1

    5
    1 2 3 6 8
    

    输出#1

    2
    
  • 输入#2

    3
    3 6 5
    

    输出#2

    -1
    
  • 输入#3

    6
    2 4 8 6 10 18
    

    输出#3

    3
    

说明/提示

In the first sample, you can use two variables b1b_{1} and b2b_{2} to perform the following sequence of operations.

  1. b1b_{1} := 11 ;
  2. b2b_{2} := b1+b1b_{1}+b_{1} ;
  3. b1b_{1} := b1+b2b_{1}+b_{2} ;
  4. b1b_{1} := b1+b1b_{1}+b_{1} ;
  5. b1b_{1} := b1+b2b_{1}+b_{2} .
首页