zhengjinyi
2024-11-15 17:27:07
看到
方案数除去
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define R read()
using namespace std;
inline int read(){
int x=0;char c=0;
while(c<'0'||c>'9') c=getchar();
while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
return x;
}
const int inf=0x3f3f3f3f,N=105;
const ll INF=0x3f3f3f3f3f3f3f3f,M=1000000007;
int n,m,k,a[N],cnt;
struct matrix{
ll s[N][N];
friend matrix operator* (matrix x,matrix y){
matrix z;
for(int i=0;i<=m;i++){
for(int j=0;j<=m;j++){
z.s[i][j]=0;
for(int k=0;k<=m;k++)
z.s[i][j]+=x.s[i][k]*y.s[k][j],z.s[i][j]%=M;
}
}
return z;
}
}A,B,E;
ll power(ll x,int y){
ll res=1;
while(y){
if(y&1) res*=x,res%=M;
x*=x,x%=M,y>>=1;
}
return res;
}
matrix power(matrix x,int y){
matrix res=E;
while(y){
if(y&1) res=res*x;
x=x*x,y>>=1;
}
return res;
}
ll qwq;
int main(){
n=R,k=R;
for(int i=1;i<=n;i++) a[i]=R,m+=a[i];
for(int i=n-m+1;i<=n;i++) cnt+=a[i];
for(int i=0;i<=m;i++) E.s[i][i]=1;
qwq=power(n*(n-1)>>1,M-2);
for(int i=0;i<=m;i++){
ll sum=3*M+1;
if(i){
B.s[i][i-1]=i*(n-m-m+i)%M*qwq%M;
sum-=B.s[i][i-1];
}
if(i<m){
B.s[i][i+1]=(m-i)*(m-i)%M*qwq%M;
sum-=B.s[i][i+1];
}
B.s[i][i]=sum%M;
}
A.s[0][cnt]=1;
A=A*power(B,k);
printf("%lld\n",A.s[0][m]);
return 0;
}