Lightoj1170-counting Perfect BST (Cattleya number)

Source: Internet
Author: User

The topic is probably to ask for a number of n different numbers to construct a two-fork sort tree of several forms.

and another classic topic n nodes two the number of different forms of a fork tree a recursive solution, in fact, the solution of these two problems are Cattleya number.

    • Dp[n] Indicates the number of scenarios with N
    • The transfer is the enumeration of the number of the root, and then into the left and right two sub-trees, the number of the two sub-tree is similar to the problem

The other is the topic must first find [1,1e10] perfect power, a total of 102,230, the input interval [a,b],b-a>=1e6, that is, the maximum number of perfect power is probably within the a=1,b=1000001 range, 1110 x Perfect power.

1#include <cstdio>2#include <cstring>3#include <Set>4#include <algorithm>5 using namespacestd;6 Long LongPowLong LongXinty) {7     Long Longres=1;8      for(intI=0; i<y; ++i) res*=x;9     returnRes;Ten } One Long Longpownum[111111]; A intPN; - intGETCNT (Long LongALong Longb) { -     return(Upper_bound (POWNUM,POWNUM+PN,B)-pownum)-(Lower_bound (pownum,pownum+pn,a)-pownum); the } - Long Longd[1111]; - intMain () { -      for(Long LongI=2; i*i<=10000000000L; ++i) { +          for(intj=2; ; ++j) { -             if(Pow (I,J) >10000000000L) Break; +pownum[pn++]=Pow (i,j); A         } at     } -Sort (pownum,pownum+PN); -Pn=unique (POWNUM,POWNUM+PN)-Pownum; -d[0]=d[1]=1; -      for(intI=2; i<1111; ++i) { -          for(intj=1; j<=i; ++j) { ind[i]+=d[j-1]*d[i-j]; -d[i]%=100000007; to         } +     } -d[0]=0; the     Long Longb; *     intT; $scanf"%d",&t);Panax Notoginseng      for(intCse=1; cse<=t; ++CSE) { -scanf"%lld%lld",&a,&b); theprintf"Case %d:%lld\n", cse,d[getcnt (A, b)]);  +     } A     return 0; the}

Lightoj1170-counting Perfect BST (Cattleya number)

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.