1011 simply change it.
# Include <iostream> # include <algorithm> Using Namespace STD; # define Max 64 Int Sticks [Max]; Bool Used [Max]; Int Sticknum, Plen, N; Bool Compare ( Int A, Int B ){ Return A> B ;} // Match from beginindex. The next step is to match the stick of matchlen. hasmatch stick has been matched before. Bool DFS (Int Beginindex, Int Matchlen, Int Hasmatch ){ If (Matchlen = 0) {hasmatch ++; If (Hasmatch = 4 ){ Return True ;} For (Beginindex = 0; used [beginindex]; beginindex ++); used [beginindex] = True ; If (DFS (beginindex + 1, Plen-sticks [beginindex], hasmatch )) Return True ; Used [beginindex] =False ; Return False ;} Else { If (Beginindex> N-1) Return False ; For ( Int I = beginindex; I <n; I ++ ){ If (Used [I]) Continue ; If (Sticks [I]> matchlen) Continue ;If (I> 0 & sticks [I] = sticks [I-1] &! Used [I-1]) Continue ; Used [I] = True ; If (DFS (I + 1, matchlen-sticks [I], hasmatch )) Return True ; Used [I] = False ;}} // Return False ;} Int Main ( Int Argc, Char * Argv []) {// Freopen ("I: // in.txt", "r", stdin ); Int Sum = 0; Bool OK; Int I, J; Int C; scanf (" % D ", & C ); For (J = 0; j <C; j ++) {OK = False ; Scanf (" % D ", & N); sum = 0; For (I = 0; I <n; I ++) {scanf (" % D ", & Sticks [I]); sum + = sticks [I];} If (Sum % 4! = 0) {OK =False ;} Else {Sort (sticks, sticks + N, compare); Plen = sum/4; used [0] = True ; If (DFS (0, Plen-sticks [0], 0) {OK = True ;} // Used [0] = false; } Printf (" % S \ n ", OK? " Yes ":" No "); Memset (used, False , Sizeof (Used ));} Return 0 ;}