HDU 4165 DP

Source: Internet
Author: User

Can be done with Cattleya number

The following analysis turns from: Http://www.cnblogs.com/kevinACMer/p/3724640.html?utm_source=tuicool

The problem did not respond to the question before it was to ask for the number of Cattleya, when it was a recursive to think. Later checked the next HDU4165, the results of a look at the headline is said to be Cattleya number, I think about it, it is really so. Mainly for the Cattleya number of use not much, also did not immediately react to come over. The following is a description of my ideas, and then the number of Cattleya to do some additional.

Test instructions: There are n tablets of the same pill in the jar, and at the beginning the pills are all intact. Then a day to take any one of them, if the pill is a complete whole piece, then he will eat a half piece, and then throw the remaining half of the pieces back to the jar, if it happens to be half a piece, then he directly eat out of the half of the film. Apparently 2N days later, he ate all the n tablets and how many different ways of eating it.

The order of my thoughts was this: discovering that for a state, its next state would have two possibilities (and of course there is only one possibility), then it might be easy to think of the two as long as the recursion goes down. Then consider that these two may be just the next state I may take the whole pill, or I may eat only a half tablets. So recursion apparently designed two parameters, the number of complete pills and the number of only half tablets. A two-dimensional array of dp[i][j] is opened, indicating how many different ways to eat when there is only half of the pills in the jar with the whole pill and the J tablets.

Then the recursive process should be relatively easy to come out: dp[i][j]=dp[i-1][j+1]+dp[i][j-1], recursive description: For the current dp[i][j] This state, it will appear next two fork, one possibility, next come up with a complete pill, Then eat half, throw back half, and then become dp[i-1][j+1] this state, but also one may be just take out is only a half tablets, then became dp[i][j-1] this state. Then since DP defines the number of scenarios, it is clear that the number of scenarios added to these two subsequent states is the number of scenarios for the previous state.

Of course, the next is to give the two-dimensional DP to the initial value, obviously dp[1][0]=1, and then found in fact dp[1][i]=i+1 (can be understood: when the jar is only a half-shaped pill and 1 tablets of complete pills, for the number of solutions, in fact, the main thing is to see the whole pill in the first few days to eat, For a total of i+1 days, it is clear that the number of C (i+1) (1) programs. Then I in Dp[i][j] is the equivalent of starting from 2 to recursion. For J, when J is 0 o'clock, it corresponds to the next state in fact there is only one possibility, that is dp[i][0]=dp[i-1] [1], so J began to recursion from 1. The specific code is as follows:

1#include <stdio.h>2#include <string.h>3#include <algorithm>4#include <cstring>5 #definell Long Long6ll dp[ +][ +];7 voidinit () {8      for(intI=0;i< -; i++) dp[1][i]=i+1;9      for(intI=2; i<= -; i++){Tendp[i][0]=dp[i-1][1]; One          for(intj=1; j+i<= -; j + +){ Adp[i][j]=dp[i-1][j+1]+dp[i][j-1]; -         } -     } the } - intMain () - { -     intN; + init (); -      while(SCANF ("%d", &n)! =EOF) { +         if(n==0) Break; Aprintf"%i64d\n", dp[n][0]); at     } -     return 0; -}

This is the way of thinking, relatively simple recursion. But then see some problems, for the subject, in fact, is to seek Cattleya number.
We think this way: the test instructions transformation of the subject can be understood, there are n red ball, n white ball, ask the number of 2N ball, and from the first ball to any ball in the back of the number of red balls must not be less than the number of white balls (understanding that the white ball is a red ball, a red ball produced a white ball). Then this becomes a typical application of the Cattleya number.

Number of Cattleya:

Make H (0)=1, H (1) =1, Catalan number satisfies the recursive type:

H (N)=H0)*h (N-1) + H (1) *h (N-2) + H (n-1) H (0>=2)

=c ( 2n,n) / (n +1=1,2,3,)       

Alternative recursion: H (n)=((4*n-2)/(n+1))*h (n-1 );

There are a lot of combinatorial mathematics. The combined structure can be counted by the number of Catalain. The following are examples of C-N= 3 and c-N= 4:

    • C N indicates the number of Dyck word with a length of 2n . Dyck Word is a string of n x and n y, and all partial strings satisfy the number of x greater than or equal to Y. The following is a Dyck words with a length of 6:

xxxyyy xyxxyy xyxyxy Xxyyxy xxyxyy

    • Replace the x in the previous example with an opening parenthesis, y with a closing parenthesis, andCn for all the number of legal expressions that contain the n set of parentheses:

((())) ()(()) ()()() (())() (()())

    • C N indicates the number of two-fork trees with n+1 leaves.

  • C n is the number of all two-forked trees with n branching nodes that are different in their structure. (a binary tree with a root is full when and only if each node has two subtrees or no subtree.) )
  • proof:

    1 for the stack, 0 for the stack, it can be converted to a 2n bit, containing n 1, n 0 of the binary number, to meet from left to right scan to any one, the number of 0 is not more than 1. It is obvious that the 2n bit binary number with n 1, n 0 has a total of one, and the following considerations do not satisfy the required number.

    Consider a 2n bit binary number with n 1, n 0, scan to section 2m+1 bits are m+1 0 and m 1 (it is easy to prove that this is the case), then there must be n-m 1 and n-m-1 0 in the following 0-1 permutations. Change 2m+2 and its subsequent parts 0 to 1 and 1 to 0, corresponding to a binary number of n+1 0 and n-1 1. and vice versa (similar thinking proves that both one by one correspond).

    thereby. The certificate is completed.

      • C n for all monotone paths that do not cross the diagonal in the n x n Grid The number of . A monotone path starts at the lower-left corner of the lattice point and ends in the upper-right corner of the lattice point, with each step up or to the right. Calculating the number of such paths is equivalent to calculating the number of Dyck Word: X for "right" and Y for "up". For N = 4:
      •                                                                            
      • C n is the number of methods that divide the convex polygons of the n + 2 edges into triangles by linking vertices. In the case of n= 4:

        C n represents the number of permutations in and out of the stack for {1, ..., n }. A permutation W is sequentially in and out of the stack when s ( w ) = (1, ..., n ), where the s ( w ) recursion is defined as follows: Make w = UNV , where n is the largest element of W , u and v for shorter series; again s ( w ) = s ( U ) S ( v ) n , where S is the unit element for all series with one element.
      • C n represents the number of non-intersecting partitions for the collection {1, ...,n}. Then,Cn is never greater than the nth Bell number. C N also represents the number of non-intersecting divisions of the collection {1, ..., 2n}, where each paragraph has a length of 2. Combined with these two conclusions, it is possible to use the mathematical induction methodto prove that all of the free cumulants of degree more than 2 of Thewigner semicircle Laware Zero. This is important infree probabilitytheory and the theory ofrandom matrices.
      • C n indicates the number of methods to fill a ladder -like shape with n rectangles with a height of n. For the case of n = 4:

HDU 4165 DP

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.