比赛 |
2022级数学专题练习赛7 |
评测结果 |
AAAAAAAAAA |
题目名称 |
物品染色 |
最终得分 |
100 |
用户昵称 |
op_组撒头屯 |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2023-01-30 19:23:05 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define si set<int>
#define qi queue<int>
#define sti stack<int>
#define fi first
#define se second
#define pb push_back
#define clr(f,n) memset(f,0,sizeof(int)*(n))
#define cpy(f,g,n) memcpy(f,g,sizeof(int)*(n))
const int N=100000+5;
const ll mod=1000000007;
int n,m;
int a[N];
ll fac[N],inv[N],pw[N];
ll fst(ll x,ll y){
ll ans=1;
while(y){
if (y&1)ans=ans*x%mod;
x=x*x%mod;
y>>=1;
}
return ans;
}
ll C(int x,int y){
return fac[x]*inv[y]%mod*inv[x-y]%mod;
}
int main(){
freopen ("dye.in","r",stdin);
freopen ("dye.out","w",stdout);
scanf("%d%d",&n,&m);pw[0]=fac[0]=1;
for (int i=1;i<=n;i++){
pw[i]=pw[i-1]*(m-1)%mod;
fac[i]=fac[i-1]*i%mod;
}
inv[n]=fst(fac[n],mod-2);
for (int i=n-1;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;
for (int i=1;i<=m;i++){
int x;scanf("%d",&x);a[x+1]++;
}
for (int i=1;i<=n;i++)a[i]+=a[i-1];
ll ans=fst(m,n),now=0;
for (int i=n;i>=1;i--){
if (!a[i])break;
now=C(n,i)*a[i]%mod*pw[n-i]%mod;
ans=(ans+mod-now)%mod;
}
printf("%lld\n",ans);
return 0;
}