Test instructions
In simple terms, a tree is created, and the path of the root to each leaf node is arranged differently,
And each root-to-leaf path has n blue and n red edges.
The number of nodes in the generated tree.
1<=n<=10^6
Exercises
Simple count.
Obviously, the color of the edges of the top n layers is arbitrary, so the layer I is the 2^i point.
For the post-n layer, it can be transferred directly from the previous layer.
Since you already know the number of the previous layer, then if you now expand two edges per point,
So in the state of the previous layer, the number of a certain color has reached N, and one side is not expandable.
So subtract 2*c (i-1,n).
1 2 3 4 5 6 7 8 910111213141516171819202122232425262728293031323334353637 |
#include <cstdio>#include <cstring>typedef Long Long Lint;Const int N = 2000000, MO = 1000000007;int N,n2,ps,pr[n],fc[n],iv[n],ans;int Powmod(int A,int b){int s = 1; for(; B;b>>=1){if(b&1) s = (Lint) s*a%MO;a = (Lint) a*a%MO;}return s;}void Init(int N){int i,j; for(fc[0]=1, I=1; I<=N;i++) Fc[i] = (lint) Fc[i-1]*I%MO; for(Iv[n]=Powmod (Fc[n],mo-2), I=N;i>=1; I--) Iv[i-1] = (Lint) iv[i]*I%MO;}inline int getc(int A,int b){return (Lint) Fc[a]*Iv[a-b]%MO*Iv[b]%MO;}int Main(){scanf ("%d",&n); N2 = N<<1;Init (n*2);int i,j,t=1, C=1;ans = 1; for(i=1; I<=N;i++) T = ((lint) T<<1)%MO, ans = ((lint) ans+t)%MO; for(i=N+1; I<=N2;i++) T = ((lint) T<<1)-( (Lint) getc (i-1, N)<<1))%MO, ans = ((lint) ans+t)%MO;printf ("%d\ n", (ans+MO)%MO);return 0;} |
Bubble Cup 8 Finals H. Bots (575H)