P2675 "The digital game of the t3-triangle Holy Land"

Source: Internet
Author: User

Portal

Consider the contribution of the number to the answer at the top of each position

And then it's easy to see:

If there are n layers, the number of positions I contributes to the answer is C (n-1,i)

Then there is the obvious greedy approach:

The larger the number, the greater the middle, so that its contribution will be as large as possible.

Then consider the C (i,j)

Because n is large and the modulus is very small

So we need to use Lucas ' theorem to find C.

C (n,m) = C (n/mo,m/mo) *c (N%MO,M%MO)

When C is relatively small, it can be calculated directly using factorial and factorial inverse elements.

#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>using namespaceStd;typedefLong LongLl;inlineintRead () {intx=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9')    {        if(ch=='-') f=-1; CH=GetChar (); }     while(ch>='0'&&ch<='9') {x= (x<<1) + (x<<3) + (ch^ -); CH=GetChar (); }    returnx*F;}Const intn=1e6+7, mo=1e4+7;intN;ll Inv[mo],fac[mo];//Note Long LongInlinevoidPre ()//preprocessing factorial and factorial inverse elements{fac[0]=1;  for(intI=1; i<mo;i++) fac[i]=fac[i-1]*i%mo; inv[0]=inv[1]=1;  for(intI=2; i<mo;i++) inv[i]= (mo-mo/i) *inv[mo%i]%mo;  for(intI=1; i<mo;i++) inv[i]=inv[i]*inv[i-1]%mo;//To find factorial inverse element}inline ll C (ll X,ll y) {if(x<y)return 0; if(X&LT;MO&AMP;&AMP;Y&LT;MO)returnFac[x]*inv[y]%mo*inv[x-y]%mo;//c Small, direct request    returnC (X%mo,y%mo) *c (x/mo,y/mo)%mo;} inline ll F (ll X) {returnX>=mo? x-mo:x; }//for a number that doesn't exceed 2*mo, it's going to be quicker.intMain () {pre (); N=read (); ll ans=0;  for(intI=1; i<=n;i++) ans=f (ans + C (n-1, (I-1) >>1) *i%mo); printf ("%lld", ans); return 0;}

P2675 "The digital game of the t3-triangle Holy Land"

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.