[Catlan number] [number theory]

Source: Internet
Author: User

The first few catlands: C0 = 1, while

C1 = 1, C2 = 2, C3 = 5, C4 = 14, C5 = 42,

C6 = 132, C7 = 429, C8 = 1430, C9 = 4862, C10 = 16796,

C11 = 58786, C12 = 208012, C13 = 742900, C14 = 2674440, C15 = 9694845.

The following formula is used to calculate the number of catlands:

  1. H (n) = H (n-1) * (4 * N-2)/(n + 1)
  2. H (n) = H (0) * H (n-1) + H (1) * H (n-2) +... + H (n-1) H (0) (N> = 2)
  3. H (n) = C (2n, N)/(n + 1) (n = 0, 1, 2 ,...)
  4. H (n) = C (2n, n)-C (2n, n + 1) (n = 0, 1, 2 ,...)

The following is an operation of the number of catlands: It can accurately calculate the number of catlands within 100.
/* For large numbers, the following algorithm should be used. Formula Used: H (n) = H (n-1) * (4 * N-2)/(n + 1 ); * // 0 Ms # include <iostream> # include <cstring> # include <stdio. h> using namespace STD; # define max 100 // maximum 10000 ^ 100, maximum 400 bits # define base 10000 void multiply (int A [], int Max, int B) // multiplication of large numbers, pay attention to the parameter passing {int I, array = 0; for (I = Max-1; I> = 0; I --) {array + = B * A [I]; A [I] = array % base; // the four-digit array with each digit storing a large number array/= base ;}} void divide (int A [], int Max, int B) // simulate the division of large numbers {int I, DIV = 0; for (I = 0; I <Max; I ++) {DIV = div * base + A [I]; A [I] = div/B; div % = B ;}} int main () {int A [101] [Max], I, n; memset (A [1], 0, max * sizeof (INT); for (I = 2, a [1] [MAX-1] = 1; I <101; I ++) // high coordinate storage of large numbers low position {memcpy (A [I], a [I-1], Max * sizeof (INT); // H [I] = H [I-1]; multiply (A [I], Max, 4 * I-2); // H [I] * = (4 * I-2); divide (A [I], Max, I + 1); // H [I]/= (I + 1);} while (CIN> N) {for (I = 0; I <Max & a [n] [I] = 0; I ++); // remove the number 0 before the array. Cout <a [n] [I ++]; // output the first non-zero number for (; I <Max; I ++) {printf ("% 04d ", a [n] [I]); // output the number following it, and each of them must be 4 characters in length! (32767)} cout <Endl;} return 0 ;}

I am very clear about the specific use of other blogs.
Below, I will only write what I think is a little interesting ......... 12 people stand in two rows of high and low, each row of people must be arranged in the order from low to high, and the second person in the first row must be tall. How many methods are available. We can think of this question as follows: 0 indicates in the first row, and 1 indicates in the second row. For example, 000000111111 indicates 1 2 3 4 5 6 7 8 9 10 11 12000110001111 indicates 1 2 3 6 7 8 4 5 9 10 11 12. how many conditions are arranged, it is obviously a problem of going into and out of the stack. So the answer to the question is catlan number (6)



[Catlan number] [number theory]

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.