The application of HDU5763 Cattleya number

Source: Internet
Author: User

Attach the topic Link: http://acm.hdu.edu.cn/showproblem.php?pid=5673, the main idea of the problem is a robot at the origin of the coordinates, the robot can choose to go to the left to the right to rest a second, but not to the negative half axis, Now that the robot has gone through a series of motions and returned to the origin of the coordinates, ask how many cases you can make the robot reach the origin of the coordinates.

Analysis: Since the robot starts at the origin of the coordinates at the end of the coordinate origin, so we can know the number of steps to the left of the robot and the number of steps to the right, and the maximum is N/2, so we enumerate the robot to the right to walk the number of steps I, from the N method to choose 2*i not rest point of the scheme number is Then we need to know the number of legitimate 2*i of the robot, and think carefully we find that the number of programs and the number of parentheses is very similar, and the number of parentheses matches is exactly cata (i), so the final answer is Sigma (C (n, 2*i) *cata (i)) 0<=i <=N/2, the code is as follows:

#include <cstdio>#include<cstring>#include<algorithm>#include<iostream>using namespaceStd;typedefLong LongLL; LL M=1000000007;Const intMAXN =1000000+ -; LL NFIC[MAXN*2], rev_nfic[maxn*2]; LL CATA[MAXN]; ll Qk_mod (ll A, ll b) {ll res=1;  while(B >0){        if(b&1) Res= (res*a)%M; A= (a*a)%l; b>>=1; }    returnRes;} ll Com (ll N, ll m) {ll res=Nfic[n]; Res= res*rev_nfic[m]%M; Res= res*rev_nfic[n-m]%l; returnRes;}intMain () {intT; scanf ("%d", &T); nfic[0] =1; rev_nfic[0] =1;  for(intI=1; i<=2*1000000+3; i++) {Nfic[i]= (i*nfic[i-1])%M; Rev_nfic[i]= Qk_mod (Nfic[i], M-2); }     for(intI=0; i<=1000000; i++) {Cata[i]= Com (2*i, i) *qk_mod (i+1, M-2)%l; }     while(t--) {        intN; scanf ("%d", &N); LL Res=0;  for(intI=0; i<=n/2; i++) {res= (res + Com (n,2*i) *cata[i])%l; } cout<<res<<Endl; }    return 0;}

The application of HDU5763 Cattleya number

Related Article

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.