preface
I found a big guy to go whoring to a number to play the game. Some questions were not written or I didn't write them.
Currently only: 10041005100710081011
Topic
Title Link: https://acm.hdu.edu.cn/contests/contest_show.php?cid=990
1004 Link with Balls
General idea of the topic
There are two kinds of boxes n n n, the color of the ball in each box is different
- First, second i i i boxes can be taken out i k ( k ∈ N ) ik(k\in N) ik(k ∈ N) balls
- Second kind i i i boxes can be taken out no more than i i i balls
Seek out m m Number of schemes for m balls.
1 ≤ T ≤ 1 0 5 , 1 ≤ n , m ≤ 1 0 6 1\leq T\leq 10^5,1\leq n,m\leq 10^6 1≤T≤105,1≤n,m≤106
Problem solving ideas
Derived from the generating function, the function of the first kind of ball is
1
−
x
i
1
−
x
\frac{1-x^i}{1-x}
1 − x1 − xi, the function of the second ball is
1
1
−
x
i
\frac{1}{1-x^i}
1 − xi1, it is found that multiplication can offset. The final multiplication is
(
1
−
x
n
)
(
1
1
−
x
)
n
+
1
(1-x^n)(\frac{1}{1-x})^{n+1}
(1−xn)(1−x1)n+1
And then come back
(
n
+
m
n
)
−
(
m
−
1
n
)
\binom{n+m}{n}-\binom{m-1}{n}
(nn+m)−(nm−1)
Just fine
code
#include<cstdio> #include<cstring> #include<algorithm> #define ll long long using namespace std; const ll N=2e6+10,P=1e9+7; ll T,inv[N],fac[N],n,m; ll C(ll n,ll m) {return fac[n]*inv[m]%P*inv[n-m]%P;} signed main() { inv[1]=1; for(ll i=2;i<N;i++)inv[i]=P-inv[P%i]*(P/i)%P; inv[0]=fac[0]=1; for(ll i=1;i<N;i++)fac[i]=fac[i-1]*i%P,inv[i]=inv[i-1]*inv[i]%P; scanf("%lld",&T); while(T--){ scanf("%lld%lld",&n,&m); ll ans=C(m+n,n); m-=n+1; if(m>=0)ans=(ans-C(m+n,n)+P)%P; printf("%lld\n",ans); } }
1005 Link with EQ
General idea of the topic
n
n
n Lattice stools. At the beginning, the first student will randomly choose a position to sit down, and the rest will choose a position farthest from the existing students to sit down. Ask for no students around the place. Look at how many students have sat down.
1
≤
T
≤
1
0
5
,
1
≤
n
≤
1
0
6
1\leq T\leq 10^5,1\leq n\leq 10^6
1≤T≤105,1≤n≤106
Problem solving ideas
set up f i f_i fi , means only i i How many people can i do when i have a grid and there are students on each side? This can be very easy d p dp dp come out.
Then mainly consider the seat of the first person, judge the head and tail positions, and then the rest are right f f f find a prefix sum and you can calculate it quickly.
Time complexity O ( n + T log P ) O(n+T\log P) O(n+TlogP)
code
#include<cstdio> #include<cstring> #include<algorithm> #define ll long long using namespace std; const ll N=1048576,P=1e9+7; ll T,n,f[N],g[N],s[N]; ll power(ll x,ll b){ ll ans=1; while(b){ if(b&1)ans=ans*x%P; x=x*x%P;b>>=1; } return ans; } signed main() { for(ll i=3;i<N;i++){ ll mid=(i+1)/2; f[i]=f[mid-1]+f[i-mid]+1; s[i]=(s[i-1]+f[i]*2)%P; } for(ll i=1;i<N;i++)g[i]=f[i]+2; scanf("%lld",&T); while(T--){ scanf("%lld",&n); if(n<=2){puts("1");continue;} if(n==3){puts("666666673");continue;} ll ans=(3*(n-4)+s[n-4])%P; (ans+=g[n-2]*2+g[n-3]*2)%=P; ans=ans*power(n,P-2)%P; printf("%lld\n",ans); } return 0; }
1007 Link with Limit
General idea of the topic
Give permutation
f
f
f. Then
f
i
(
x
)
f_i(x)
fi (x) indicates
x
x
x substitution
i
i
Position after i times.
definition
g
(
x
)
=
lim
n
−
>
+
∞
1
n
∑
i
=
1
n
f
i
(
x
)
g(x)=\lim_{n->+\infty}\frac{1}{n}\sum_{i=1}^nf_i(x)
g(x)=n−>+∞limn1i=1∑nfi(x)
Ask whether for all g ( x ) ( x ∈ [ 1 , n ] ) g(x)(x\in [1,n]) g(x)(x ∈ [1,n]) are the same value.
1 ≤ n ≤ 1 0 5 1\leq n\leq 10^5 1≤n≤105
Problem solving ideas
Finally, it must be replaced into a ring. Consider whether the average value of each ring is equal
Time complexity O ( n ) O(n) O(n)
Code by our great stoorz \text{stoorz} stoorz wrote, so I didn't
1011 Yiwen with Formula
General idea of the topic
give n n A reproducible set of n numbers a a a. Find the product of the sum of all its subsets. model 998244353 998244353 998244353.
1 ≤ T ≤ 10 , 1 ≤ n ≤ 1 0 5 , ∑ n ≤ 2.5 × 1 0 5 , ∑ a i ≤ 4 × 1 0 5 1\leq T\leq 10,1\leq n\leq 10^5,\sum n\leq 2.5\times 10^5,\sum a_i\leq 4\times 10^5 1≤T≤10,1≤n≤105,∑n≤2.5×105,∑ai≤4×105
Problem solving ideas
Divide and conquer violence N T T NTT NTT calculates the number of schemes for each sum, and then modulo because it is exponential φ ( 998244353 ) \varphi(998244353) φ (998244353) therefore, it is necessary to use any modulus to rush the grass.
code
#include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #define ll long long using namespace std; const ll N=4e5*4+10,sqq=32768,p=998244352,P=998244353; const double Pi=acos(-1); struct complex{ double x,y; complex (double xx=0,double yy=0) {x=xx;y=yy;return;} }A[N],B[N],C[N],D[N]; struct Poly{ ll a[N],n; }F[20]; ll power(ll x,ll b,ll P){ ll ans=1; while(b){ if(b&1)ans=ans*x%P; x=x*x%P;b>>=1; } return ans; } complex operator+(complex a,complex b) {return complex(a.x+b.x,a.y+b.y);} complex operator-(complex a,complex b) {return complex(a.x-b.x,a.y-b.y);} complex operator*(complex a,complex b) {return complex(a.x*b.x-a.y*b.y,a.x*b.y+a.y*b.x);} complex w[N]; ll n,m,T,u[N],v[21],r[N]; void FFT(complex *f,ll op,ll n){ for(ll i=0;i<n;i++) if(i<r[i])swap(f[i],f[r[i]]); for(ll p=2;p<=n;p<<=1){ ll len=p>>1; for(ll k=0;k<n;k+=p) for(ll i=k;i<k+len;i++){ complex tmp=w[n/len*(i-k)]; if(op==-1)tmp.y=-tmp.y; complex tt=f[i+len]*tmp; f[i+len]=f[i]-tt; f[i]=f[i]+tt; } } if(op==-1){ for(ll i=0;i<n;i++) f[i].x=(ll)(f[i].x/n+0.49); } return; } void MTT(ll *a,ll *b,ll *c,ll m,ll k){ ll n=1; while(n<=m+k)n<<=1; for(ll i=0;i<n;i++){ r[i]=(r[i>>1]>>1)|((i&1)?(n>>1):0); A[i].x=A[i].y=B[i].x=B[i].y=0; C[i].x=C[i].y=D[i].x=D[i].y=0; } for(ll len=1;len<n;len<<=1) for(ll i=0;i<len;i++) w[n/len*i]=complex(cos(i*Pi/len),sin(i*Pi/len)); for(ll i=0;i<m;i++)A[i].x=a[i]/sqq,B[i].x=a[i]%sqq; for(ll i=0;i<k;i++)C[i].x=b[i]/sqq,D[i].x=b[i]%sqq; FFT(A,1,n);FFT(B,1,n);FFT(C,1,n);FFT(D,1,n); complex t1,t2; for(ll i=0;i<n;i++){ t1=A[i]*C[i];t2=B[i]*D[i]; B[i]=A[i]*D[i]+B[i]*C[i]; A[i]=t1;C[i]=t2; } FFT(A,-1,n);FFT(B,-1,n);FFT(C,-1,n); for(ll i=0;i<n;i++){ c[i]=0; (c[i]+=(ll)(A[i].x)*sqq%p*sqq%p)%=p; (c[i]+=(ll)(B[i].x)*sqq%p)%=p; (c[i]+=(ll)(C[i].x))%=p; } return; } void Mul(Poly &a,Poly &b){ MTT(a.a,b.a,a.a,a.n,b.n); a.n=a.n+b.n-1;return; } ll findq(){ for(ll i=0;i<20;i++) if(!v[i]){v[i]=1;return i;} } ll Solve(ll l,ll r){ if(l==r){ ll p=findq(); for(ll i=0;i<=u[l];i++) F[p].a[i]=0; F[p].a[0]=1;F[p].a[u[l]]=1; F[p].n=u[l]+1;return p; } ll mid=(l+r)>>1; ll ls=Solve(l,mid),rs=Solve(mid+1,r); Mul(F[ls],F[rs]);v[rs]=0;return ls; } signed main(){ scanf("%lld",&T); while(T--){ scanf("%lld",&n); bool flag=0;ll ans=1,sum=0; for(ll i=1;i<=n;i++){ scanf("%lld",&u[i]); flag|=!u[i];sum+=u[i]; } if(flag){puts("0");continue;} ll id=Solve(1,n);u[id]=0; for(ll i=1;i<=sum;i++) ans=ans*power(i,F[id].a[i],P)%P; printf("%lld\n",ans); } }