bzoj2822 [AHOI2012] Tree house ladder

Source: Internet
Author: User

Description during the summer, Little Dragon signed up for a simulated field survival combat training course to exercise physique, the first night of training, instructors gave them a problem. As the aboveground camping moisture is heavy, you must choose a tree house in the high place to camp. The tree house allocated by Dragons was built on a big tree with a height of n+1 feet (n is a positive integer), just as he was worrying about how to climb up, Found next to the heap filled with some hollow square steel (1.1), after observation and measurement, these steel cross-sectional width and height vary, but are 1-foot integer times, the instructor ordered the players to choose N Hollow Steel to build a total height of n-foot ladder to enter the tree house, the ladder each step of the height of 1 feet, width is 1 feet If these steels are of various sizes and each size is plentiful, how many ways can dragons be built? (Note: In order to avoid nadir at night, the steel hollow side must not be upward.) )

Take the tree house height of 4 feet, Ladder height n=3 ruler, for example, there are 1.2 of the 5 species of dragons shown

Construction Method:

Input

A positive integer n (1≤n≤500), indicating the height of the ladder

Output

A positive integer that represents the number of build methods. (Note: The number of construction methods can be very large.) )

Sample Input3Sample Output5HINT

1 ≤N≤

High-precision version of Cattleya ... Direct use of templates is a bit slow

#include <cstdio> #include <iostream> #define LL long long#define mx 1000using namespace Std;inline ll read () {    LL X=0,f=1;char Ch=getchar (); while (ch< ' 0 ' | |    Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();}    while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} return x*f;}     struct gaojing{int len; int a[mx+10];}    mult,ans,zero,one;inline void Set0 (gaojing &s) {s.len=1; for (int i=1;i<=mx+5;i++) s.a[i]=0;}    inline void Inputn (gaojing &a) {set0 (a);    Char Ch=getchar (); while (ch< ' 0 ' | |      Ch> ' 9 ') Ch=getchar ();        while (ch>= ' 0 ' &&ch<= ' 9 ') {a.a[a.len++]=ch-' 0 ';    Ch=getchar ();      } a.len--;    int change[mx+15];      for (int i=1;i<=a.len;i++) change[i]=a.a[i];    for (int i=1;i<=a.len;i++) a.a[i]=change[a.len-i+1];  while (a.a[a.len]==0) a.len--;}    inline void put (gaojing a) {for (int i=a.len;i>=1;i--) printf ("%d", a.a[i]); printf ("\ n");} Inline gaojing operator + (const gaojing &a,const gaojing &b) {gaojing c;set0 (c);          int Maxlen=max (A.len,b.len);              for (int i=1;i<=maxlen;i++) {c.a[i]=c.a[i]+a.a[i]+b.a[i];                if (c.a[i]>=10) {C.A[I+1]+=C.A[I]/10;            c.a[i]%=10;          }} c.len=maxlen+4;        while (!c.a[c.len]&&c.len>1) c.len--; return c;}    Inline gaojing operator * (const gaojing &a,const gaojing &b) {gaojing c;set0 (c);        for (int. i=1;i<=a.len;i++) for (int j=1;j<=b.len;j++) C.A[I+J-1]+=A.A[I]*B.A[J];      c.len=a.len+b.len+5;            for (int i=1;i<=c.len;i++) {C.A[I+1]+=C.A[I]/10;          c.a[i]%=10;    } while (!c.a[c.len]&&c.len>1) c.len--; return c;}    Inline gaojing operator ^ (const gaojing &a,int p) {gaojing ans=one,mult=a;        while (p) {if (p&1) Ans=ans*mult;        Mult=mult*mult; P>>=1; } return ans;    inline void Chushihua () {set0 (zero); zero.len=1; Set0 (one); one.len=1;one.a[1]=1;}    int N,len,now;bool mrk[1010];int prime[1010],rep[1010],mn[1010];inline void Getprime () {for (int i=2;i<=2*n;i++)        {if (!mrk[i]) Prime[++len]=i,mn[i]=len;            for (int j=1;prime[j]*i<=2*n&&j<=len;j++) {mrk[prime[j]*i]=1;            Mn[prime[j]*i]=j;        if (i%prime[j]==0) break;        }}}inline void Calc (int x,int f) {while (x!=1) {rep[mn[x]]+=f;    X/=PRIME[MN[X]];    }}int Main () {Chushihua (); ans=one;mult=one;    N=read ();    Getprime ();    for (int i=n+2;i<=2*n;i++) calc (i,1);    for (int i=1;i<=n;i++) calc (i,-1);        for (int i=2;i<=2*n;i++) {mult=mult+one;        if (Mrk[i]) Continue;else now++;    if (Rep[now]) ans=ans* (Mult^rep[now]); } put (ans);

bzoj2822 [AHOI2012] Tree house ladder

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.