传送门
题意:
一个人从0点出发,在数轴上向右走,每次有1/K的概率向右走1步,有1/K的概率向右走2步,…,有1/K的概率向右走K步
问到达Ni点的概率是多少 注:Ni==-1时,代表Ni在无穷远处
思路:
①Ni==-1,也就是无穷远处
考虑走一步能走的距离的期望是,那么由于期望的性质,不妨认为每步都走
那么看能不能到达N,就等价于看是从0,1,...这 个点哪个点出发的,
N只能从其中1个点出发到达,从而从这么多点选一个选中那个点的概率是 ,
邓神是这样证明的:
放进杜教BM板子里搞一搞,预处理前2k项答案,搞出第N项取模mod答案
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ll long long
using namespace std;
const ll mod=1e9+7;
const int N=1e5+10;
ll powmod(ll a,ll b){ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;};
namespace linear_seq
{
#define rep(i,a,n) for(int i=a;i=a;i--)
#define pb push_back
#define mp make_pari
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
typedef vector VI;
const int N=100010;
ll res[N],base[N],_c[N],_md[N];
vector Md;
void mul(ll *a,ll *b,ll k)
{
rep(i,0,k+k) _c[i]=0;
rep(i,0,k) if(a[i]) rep(j,0,k) _c[i+j]=(_c[i+j]+a[i]*b[j])%mod;
for(int i=k+k-1;i>=k;i--) if(_c[i])
rep(j,0,SZ(Md)) _c[i-k+Md[j]]=(_c[i-k+Md[j]]-_c[i]*_md[Md[j]])%mod;
rep(i,0,k) a[i]=_c[i];
}
int solve(ll n,VI a,VI b)
{
ll ans=0,pnt=0;
ll k=SZ(a);
assert(SZ(a)==SZ(b));
rep(i,0,k)_md[k-1-i]=-a[i];_md[k]=1;
Md.clear();
rep(i,0,k) if(_md[i]!=0) Md.push_back(i);
rep(i,0,k) res[i]=base[i]=0;
res[0]=1;
while((1ll<=0;p--)
{
mul(res,res,k);
if((n>>p)&1)
{
for(ll i=k-1;i>=0;i--) res[i+1]=res[i];res[0]=0;
rep(j,0,SZ(Md)) res[Md[j]]=(res[Md[j]]-res[k]*_md[Md[j]])%mod;
}
}
rep(i,0,k) ans=(ans+res[i]*b[i])%mod;
if(ans<0) ans+=mod;
return ans;
}
VI BM(VI s)
{
VI C(1,1),B(1,1);
ll L=0,m=1,b=1;
rep(n,0,SZ(s))
{
ll d=0;
rep(i,0,L+1) d=(d+(ll)C[i]*s[n-i])%mod;
if(d==0) ++m;
else if (2*L<=n)
{
VI T=C;
ll c=mod-d*powmod(b,mod-2)%mod;
while(SZ(C)ans;
ll dp[N<<1];
ll n,k;
int main()
{
int t ;
scanf("%d",&t);
while(t--)
{
scanf("%lld%lld",&k,&n);
if(n==-1)
{
printf("%lld\n",powmod(k+1,mod-2)*2%mod);
continue;
}
else
{
ll p=powmod(k,mod-2);/
dp[0]=1;
ans.clear();
ans.push_back(dp[0]);
for(int i=1;i<=2*k;i++)
{
dp[i]=0;
for(int j=i-1;j>=max(i-k,0*1ll);j--)
{
dp[i]=(dp[i]+p*dp[j]%mod)%mod;
}
ans.push_back(dp[i]);
}
printf("%lld\n",linear_seq::gao(ans,n));
}
}
return 0;
}