记录编号 365707 评测结果 AAAAAAAAAA
题目名称 1284.[HNOI 2004] 树的计数 最终得分 100
用户昵称 GravatarFoolMike 是否通过 通过
代码语言 C++ 运行时间 0.004 s
提交时间 2017-01-21 14:58:30 内存使用 0.30 MiB
显示代码纯文本
#include<cstdio>
#include<cmath>
using namespace std;
const int N=1010;
int n,a[N],p[N],cnt;bool isp[N];
void init(){
	for (int i=2;i<N;i++)
	if (!isp[i]){
		p[++cnt]=i;
		for (int j=i+i;j<N;j+=i) isp[j]=1;
	}
}
int Mi[N];
void mul(int x){
	for (int i=1;i<=cnt;i++)
		while (!(x%p[i])) Mi[i]++,x/=p[i];
}
void div(int x){
	for (int i=1;i<=cnt;i++)
		while (!(x%p[i])) Mi[i]--,x/=p[i];
}
int main()
{
	freopen("ctree.in","r",stdin);
	freopen("ctree.out","w",stdout);
	init();
	scanf("%d",&n);
	unsigned long long ans=1;
	int sum=0;
	for (int i=1;i<n-1;i++) mul(i);
	for (int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if (n>1&&!a[i]) ans=0;
		sum+=a[i];
		for (int j=1;j<a[i];j++) div(j);
	}
	if (sum!=n*2-2) ans=0;
	for (int i=1;i<=cnt;i++)
	if (Mi[i]<0) ans=0;
		else ans=ans*pow(p[i],Mi[i]);
	printf("%lld\n",ans);
	return 0;
}