Codeforces round #171 (Div. 2) (complete)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.