教科书般的亵渎
2019-05-28 21:02 一只弱鸡丶 阅读(227) 评论(0) 编辑 收藏 举报#include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <algorithm> #include <iostream> using namespace std; #define ll long long #define re register const int mod=1e9+7; inline void read(ll &a) { a=0; int d=1; char ch; while(ch=getchar(),ch>'9'||ch<'0') if(ch=='-') d=-1; a=ch^48; while(ch=getchar(),ch>='0'&&ch<='9') a=(a<<3)+(a<<1)+(ch^48); a*=d; } ll f[55],a[55]; inline void init() { f[0]=1; for(re int i=1;i<=54;i++) f[i]=1ll*f[i-1]*i%mod; } inline ll quickmod(ll x,int y) { ll res=1; ll base=x%mod; while(y) { if(y&1) res=res*base%mod; base=base*base%mod; y>>=1; } return res; } inline ll solve(ll n,int m) { ll ans=0; if(n<=m+2) { for(re int i=1;i<=n;i++) (ans+=quickmod(i,m))%=mod; return ans; } ll pos=1,base=0,t; for(re int i=1;i<=m+2;i++) (pos*=(n-i))%=mod; for(re int i=1;i<=m+2;i++) { (base+=quickmod(i,m))%=mod; t=pos*quickmod(n-i,mod-2)%mod; t=t*quickmod(f[m+2-i]*f[i-1],mod-2)%mod; if((m+2-i)&1) ans=((ans-base*t%mod)%mod+mod)%mod; else ans=(ans+base*t%mod)%mod; } return ans; } int main() { init(); int T; scanf("%d",&T); while(T--) { ll n; int m; read(n); scanf("%d",&m); for(re int i=1;i<=m;i++) read(a[i]); sort(a+1,a+1+m); ll ans=0; for(re int i=0;i<=m;i++) { (ans+=solve(n-a[i],m+1))%=mod; for(re int j=i+1;j<=m;j++) ans=((ans-quickmod(a[j]-a[i],m+1))%mod+mod)%mod; } printf("%lld\n",ans); } return 0; }