/*
It is said that it is a classic deep search and pruning question, and I do not feel that there is a hidden place to pruning
In fact, we have already subconsciously optimized a lot of things during coding, and we are not necessarily aware of it.
Good habits are useful.
*/
# include iostream >
# include algorithm >
# define maxn 64
using namespace STD;
int N, Len, M; // Len indicates the length of the original stick, M is the number of original sticks
int S [maxn], MK [maxn];
bool flag;
int CMP ( int , int B)
{< br> return A > B;
}
Void DFS ( Int K, Int Sum, Int CNT)
{
If (CNT = M)
Flag = True ;
Else If (Sum = Len)
DFS ( 0 , 0 , CNT + 1 );
Else
For ( Int Pre = - 1 , I = K; I < N; I ++ )
If ( ! MK [I] && S [I] ! = Pre && S [I] + Sum <= Len)
{
Pre = S [I];
MK [I] = True ;
DFS (I + 1 , Sum + S [I], CNT );
MK [I] = False ;
If (K = 0 | Flag)
Return ;
}
}
Int Main ()
{
Int Sum, I;
While (Scanf ( " % D " , & N) ! = EOF && N)
{
Flag = False ;
Sum = 0 ;
For (I = 0 ; I < N; I ++ )
{
Scanf ( " % D " , & S [I]);
Sum + = S [I];
}
Sort (S, S + N, CMP );
For (Len = S [ 0 ]; Len < SUM; Len ++ )
If (Sum % Len = 0 )
{
M = Sum / Len;
Memset (MK, 0 , Sizeof (MK ));
DFS ( 0 , 0 , 0 );
If (FLAG)
Break ;
}
Printf ( " % D \ n " , Flag ? Len: Sum );
}
Return 0 ;
}