D: Status DP, DP [s] indicates the minimum number of boxes required to reach the S state. One key condition is that the number in sequence a is generated one by one, so how can we transfer it?
Int DFS (INT flag) {If (DP [flag]! =-1) return DP [flag]; If (flag = 1) return DP [flag] = 1; int ans = inf; int bits = _ builtin_popcount (FLAG ); revp (I, n-1, 0) {If (flag & Two (I) {int to = (flag ^ two (I) | two (I-1 ); // remove the number of current I, plus the state of the I-1, because the number produced on the previous one must be I-1 rep (J, I) rep (K, J + 1) {if (a [I] = A [J] + A [k]) {int TMP = DFS (to | two (j) | two (k )); // if the number of I consists of the numbers J and K, the numbers must be in if (TMP! = Inf) ans = min (ANS, max (TMP, BITs) ;}} break ;}dp [flag] = ans; return ans ;} int main () {CIN> N; rep (I, n) CIN> A [I]; memset (DP,-1, sizeof (DP )); int ans = DFS (two (n-1); If (ANS = inf) puts ("-1"); else printf ("% d \ n", ANS ); return 0 ;}
E: greedy, from right to left hit l consecutive 1, you can reduce the total number of L-2 (L> = 2)