QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#36030#990. Colorful ComponentsFroggyguaWA 20ms4748kbC++171.8kb2022-06-22 21:26:532022-06-22 21:28:30

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-06-22 21:28:30]
  • 评测
  • 测评结果:WA
  • 用时:20ms
  • 内存:4748kb
  • [2022-06-22 21:26:53]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
#define N 305
typedef long long ll;
int n,m,cnt[N],g[N][N],C[N][N],w[N],pw[N][N];
int fac[N],ifac[N];
int qpow(int a,int b){
	int ans=1;
	while(b){
		if(b&1)ans=1LL*ans*a%mod;
		a=1LL*a*a%mod;
		b>>=1;
	}
	return ans;
}
void init(int n){
	fac[0]=1;
	for(int i=1;i<=n;++i){
		fac[i]=1LL*fac[i-1]*i%mod;
	}
	ifac[n]=qpow(fac[n],mod-2);
	for(int i=n-1;i>=0;--i){
		ifac[i]=1LL*ifac[i+1]*(i+1)%mod;
	}
	w[1]=1;
	for(int i=2;i<=n;++i){
		w[i]=qpow(i,i-2);
	}
	C[0][0]=1;
	for(int i=1;i<=n;++i){
		C[i][0]=1;
		for(int j=1;j<=i;++j){
			C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
		}
	}
	g[0][0]=1;
	for(int i=1;i<=n;++i){
		for(int k=1;k<=i;++k){
			for(int j=1;j<=min(i,m);++j){
				g[i][k]=(g[i][k]+1LL*g[i-j][k-1]*w[j]%mod*C[i][j]%mod*j)%mod;
			}
		}
	}
	for(int i=1;i<=n;++i){
		for(int k=1;k<=i;++k){
			g[i][k]=1LL*g[i][k]*ifac[k]%mod;
		}
	}
	for(int i=0;i<=n;++i){
		pw[i][0]=1;
		for(int j=1;j<=n;++j){
			pw[i][j]=1LL*pw[i][j-1]*i%mod;
		}
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m;
	vector<int> col;
	for(int i=1;i<=n;++i){
		int x;
		cin>>x;
		++cnt[x];
		if(cnt[x]==1)col.push_back(x);
	}
	init(n);
	if(col.size()==1){
		cout<<(n==m?w[n]:0)<<'\n';
		return 0;
	}
	int ans=0;
	for(int all=col.size();all<=n;++all){
		static int dp[N];
		memset(dp,0,sizeof(dp));
		dp[0]=1;
		int tot=0;
		for(auto c:col){
			int sz=cnt[c];
			static int h[N];
			for(int i=0;i<=tot+sz;++i)h[i]=0;
			for(int i=0;i<=tot;++i){
				for(int j=1;j<=sz&&i+j<=all;++j){
					h[i+j]=(h[i+j]+1LL*dp[i]*g[sz][j]%mod*pw[all-j][j-1])%mod;
				}
			}
			tot+=sz;
			for(int i=0;i<=tot;++i)dp[i]=h[i];
		}
		ans=(ans+1LL*dp[all]*qpow(n,(int)col.size()-2))%mod;
	}
	cout<<ans<<'\n';
	return 0;
}



Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3660kb

input:

5 3
1
1
3
1
5

output:

125

result:

ok "125"

Test #2:

score: 0
Accepted
time: 2ms
memory: 3556kb

input:

4 2
2
1
1
1

output:

7

result:

ok "7"

Test #3:

score: -100
Wrong Answer
time: 20ms
memory: 4748kb

input:

300 16
2
2
2
4
5
1
5
3
5
4
2
1
4
4
4
5
2
1
5
4
3
4
5
3
5
5
1
3
1
1
2
5
5
3
3
2
5
2
3
2
2
4
2
2
2
4
4
2
2
4
1
3
3
4
1
3
3
4
3
4
3
5
5
4
3
3
1
2
1
2
5
2
2
4
3
3
5
3
2
4
3
5
1
4
5
5
2
3
2
3
4
4
5
5
5
5
4
5
3
2
4
4
4
3
5
3
1
1
3
5
5
4
5
2
5
5
5
2
2
2
3
1
5
4
1
4
3
5
1
4
4
2
5
2
2
4
5
3
4
3
3
4
2
5
1
1
3...

output:

200531492

result:

wrong answer 1st words differ - expected: '540253743', found: '200531492'