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<MO&&Y<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"