【NAOI】 LAMIA
预估难度 水绿
对于长度为 \(n\) 的 01 串。
有多少个不同的 01 串,其中最长的 \(1\) 连续段长度恰好为 \(k\) 且最小的连续段长度也恰好为 \(k\)。
现在请你计算 \(k=0,1,2,…,n\) 时的答案。
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6+10,mod=1e9+7;
int n,m,q,T,jie[N],ni[N],cnt;
int ksm(int x,int k){
int ans=1;
while(k){
if(k%2) ans=ans*x%mod;
x=x*x%mod;k/=2;
}return ans;
}
int c(int n,int m){
if(m<n) return 0;
return (jie[m]*ni[n]%mod)*ni[m-n]%mod;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n;cout<<1<<" ";jie[0]=1;
for(int i=1;i<N;i++) jie[i]=jie[i-1]*i%mod;
ni[N-1]=ksm(jie[N-1],mod-2);
for(int i=N-2;i>=0;i--) ni[i]=ni[i+1]*(i+1)%mod;
for(int i=1;i<n;i++){
int ans=0;
for(int j=1;j*(i+1)<=n;j++){
ans=(ans+c(j,n-(j*i)))%mod;
}
for(int j=0;j*(i+1)<=n-i;j++){
ans=(ans+c(j,n-(j*i)-i))%mod;
}
cout<<ans<<" ";
}cout<<1;
return 0;
}

浙公网安备 33010602011771号