问个问题(关于评测速度)
查看原帖
问个问题(关于评测速度)
1425622
违规用户名1425622楼主2025/7/31 18:17

qoj 评测机这么快的吗?我做这题的时候本来想先写个 5 次方测正确性,结果一交直接过了,且时限 2s 我跑 1.9s...

这是我的代码:

#include<bits/stdc++.h>
namespace Limie{
	#define x first
	#define y second
	using namespace std;
	typedef long long LL;
	typedef unsigned long long ULL;
	typedef pair<int,int> PII;
}using namespace Limie;
int n,m,mod;
int f[155][155][155],C[155][155];
signed main()
{
	int i,j,k,x,y;
	cin>>n>>m>>mod;
	if(m>=n)return cout<<0,0;
	f[1][2][0]=1;
	for(i=C[0][0]=1;i<=n;i++)
		for(j=C[i][0]=1;j<=i;j++){
			C[i][j]=C[i-1][j]+C[i-1][j-1];
			if(C[i][j]>=mod)C[i][j]-=mod;
		}
	
	for(i=1;i<m;i++)
		for(j=i+1;j<=n;j++)for(k=0;k<i;k++){
			if(!f[i][j][k])continue;
			f[i+1][j+1][k]=(f[i+1][j+1][k]+1ll*f[i][j][k]*j)%mod; 
			f[i+1][j+2][k+1]=(f[i+1][j+2][k+1]+1ll*f[i][j][k]*(j-1))%mod; 
			for(x=0;j+x<=n;x++)for(y=0;y<=k;y++)if(x||y)
				f[i+1][j+x][k-y]=(f[i+1][j+x][k-y]+1ll*C[j+x-2][j-2]*C[k][y]%mod*f[i][j][k])%mod;
		}
		
	int s=f[m][n][0];
	for(i=1;i<=n;i++)s=1ll*s*i%mod;
	cout<<s;
}

2025/7/31 18:17
加载中...