​题目传送门​​ 代码:

#include<bits/stdc++.h>
using namespace std;

typedef long long LL;
const int maxn=1000+100;
const LL mod=1e9+7;
const LL M=mod-1;

int ans[maxn];
LL fac[maxn][maxn];

LL mypow(LL a,LL b){

LL sum=1;
while(b){

if(b&1) sum=sum*a%mod;
a=a*a%mod;
b>>=1;
}
return sum;
}

int main(){

int T;
scanf("%d",&T);
for(int i=0;i<maxn;i++){

fac[i][0]=1;
for(int j=1;j<=i;j++) fac[i][j]=fac[i-1][j-1]+fac[i-1][j],fac[i][j]%=M;
}
while(T--){

int n,k;
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++) scanf("%d",&ans[i]);
sort(ans+1,ans+1+n);
LL sum=1;
for(int i=2;i<n;i++){

sum=sum*mypow(ans[i],((fac[n-1][k-1]-fac[i-1][k-1]-fac[n-i][k-1])%M+M)%M)%mod;
}
printf("%lld\n",sum);
}
}