题解:gi(pq=pqi-pqi+di
至于为什么,可以看看往上的题解
代码:
#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll N=1005,D=105,q=1e9+7; ll p[N],s[N],a[D][D],as[N]; ll read() { ll x=0;char c; for (;c<'0'||c>'9';c=getchar()); for (;c>='0'&&c<='9';c=getchar())x=x*10+c-48; return x; } ll ksm(ll x,ll y) { ll ret=1; for (;y;y/=2,(x*=x)%=q) if (y&1)(ret*=x)%=q; return ret; } void elm(ll n) { for (ll i=1;i<n;i++) { if (!a[i][i]) for (ll j=i+1;j<=n;j++) if (a[j][i]) { for (ll k=1;k<=n+1;k++) swap(a[j][k],a[i][k]); break; } ll inv=ksm(a[i][i],q-2); for (ll j=i+1;j<=n;j++) if (a[j][i]) { ll tmp=(a[j][i]*inv)%q; for (ll k=1;k<=n+1;k++) a[j][k]=((a[j][k]-a[i][k]*tmp+q)%q+q)%q; } } for (ll i=n;i;i--) { if (!a[i][i]) for (ll j=i-1;j;j--) if (a[j][i]) { for (ll k=1;k<=n+1;k++) swap(a[j][k],a[i][k]); break; } ll inv=ksm(a[i][i],q-2); for (ll j=i-1;j;j--) if (a[j][i]) { ll tmp=(a[j][i]*inv)%q; for (ll k=1;k<=n+1;++k) a[j][k]=((a[j][k]-a[i][k]*tmp+q)%q+q)%q; } } } int main() { ll d=read(),w=read(); for (ll i=1;i<=w;i++) p[i]=read(),s[i]=read(); ll sum=0;d++; for (ll i=1;i<=d;i++) { (sum+=ksm(i,d-1))%=q; ll tmp=1; for (ll j=1;j<=d;j++) (tmp*=i)%=q,a[i][j]=tmp; a[i][d+1]=sum; } elm(d); for (ll i=1;i<=d;i++) as[i]=(a[i][d+1]*ksm(a[i][i],q-2))%q; ll ans=0; for (ll i=1;i<=d;i++) { ll g=1; for (ll j=1;j<=w;j++) { ll tmp=(ksm(p[j],s[j]*i)-ksm(p[j],s[j]*i+d-i-1)+q)%q; (g*=tmp)%=q; } (ans+=(as[i]*g))%=q; } printf("%lld",ans); }