QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#85491#990. Colorful Componentswind_crossCompile Error//C++141.9kb2023-03-07 20:06:062023-03-07 20:06:08

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-07 20:06:08]
  • 评测
  • [2023-03-07 20:06:06]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
inline char nc()
{
	static char buf[1000000],*l,*r;
	return l==r&&(r=(l=buf)+fread(buf,1,1000000,stdin),l==r)?EOF:*l++;
}
template <class code>inline code read(const code &a)
{
    code x=0;short w=0;char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=nc();}
    while(isdigit(ch)) {x=(x<<3)+(x<<1)+(ch^48);ch=nc();}
    return w?-x:x;
}
void print(long long x){
	if(x<0)putchar('-'),x=-x;
	if(x>=10)print(x/10);
	putchar(x%10+48);
}
const int mod=1e9+7;
int jc[305],inv[305],fa[305],kx[305][305],t[305];
int dp1[305],pw[305][305],dp[305];
int ksm(int x,int y){
	int now=1;
	while(y){
		if(y&1)now=1ll*now*x%mod;
		x=1ll*x*x%mod;
		y>>=1;
	}
	return now;
}
int main(){
    // freopen("text.in","r",stdin);
    // freopen("text.out","w",stdout);
	int n=read(n),k=read(k);
	for(int i=1;i<=n;i++){
		pw[i][0]=1;
		for(int j=1;j<=n;j++){
			pw[i][j]=1ll*pw[i][j-1]*i%mod;
		}
	}
	fa[1]=1;
	for(int i=2;i<=n;i++)fa[i]=ksm(i,i-2);
	jc[0]=1;
	for(int i=1;i<=n;i++)jc[i]=1ll*jc[i-1]*i%mod;
	inv[n]=ksm(jc[n],mod-2);
	for(int i=n-1;i>=0;i--)inv[i]=1ll*inv[i+1]*(i+1)%mod;
	kx[0][0]=1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			for(int p=1;p<=j&&p<=k;p++){
				kx[i][j]=(kx[i][j]+1ll*kx[i-1][j-p]*fa[p]%mod*jc[j]%mod*p%mod*inv[p]%mod*inv[j-p])%mod;
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++)kx[i][j]=1ll*kx[i][j]*inv[i]%mod;
	}
	for(int i=1;i<=n;i++){
		int x=read(x);
		t[x]++;
	}
	dp[0]=1;
	int tot=0;
	for(int i=1;i<=n;++i) {
		if(!t[i])continue;
		int z=t[i];
		++tot;
		for(int j=0;j<=n;++j){
			for(int p=1;p<=z;++p){
				dp1[j+p]=(dp1[j+p]+1ll*dp[j]*kx[p][z]%mod*pw[n-z][p-1])%mod;
			}
		}
		for(int j=0;j<=n;++j)dp[j]=dp1[j],G[j]=0;
	}
	if(tot==1){
		if(k==n)printf("%d\n",ksm(n,n-2));
		else printf("0\n");
		return 0;
	}
	int ans=0;
	for(int i=tot;i<=n;++i)ans=(ans+1ll*dp[i]*ksm(n,tot-2))%mod;
	printf("%d\n",ans);
    return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:74:51: error: ‘G’ was not declared in this scope
   74 |                 for(int j=0;j<=n;++j)dp[j]=dp1[j],G[j]=0;
      |                                                   ^