UVa 580 (Recursive) Critical Mass

Source: Internet
Author: User

Test instructions

There are two boxes of uranium (U) and lead (L), which are now lined with n boxes (two boxes are enough) and require at least 3 uranium to be put together to ask how many methods of emissions are available.

Analysis:

n boxes in a row, a total of 2n in the scheme, which conforms to the requirements of the F (N) species.

F (n) can be introduced in the following two cases:

    • The first n-1 box is placed to meet the requirements, the nth box can be placed u can also be placed L, a total of 2xf (n-1) in the scheme
    • The first n-1 box does not meet the requirements, to make the first n boxes meet the requirements, the first n-2, n-1, n boxes must be U. And because of the previous hypothesis, the first n-3 box must be L (otherwise the first n-1 box satisfies the requirements). So we make sure the last four boxes are luuu, the front n-4 box as long as not contain three consecutive U. Total 2n-4-f (n-4) in the scheme

Synthetic, f (n) = 2XF (n-1) + 2n-4-f (n-4)

1#include <cstdio>2typedefLong LongLL;3 4LL f[ *];5 6 intMain ()7 {8     intN;9f[3] =1, f[4] =3;Ten      for(inti =5; I <= -; ++i) F[i] =2*f[i-1]-f[i-4] + (1<< (I-4)); One      while(SCANF ("%d", &n) = =1&&N) Aprintf"%lld\n", F[n]); -  -     return 0; the}
code June

UVa 580 (Recursive) Critical Mass

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.