计数训练之二
作者:互联网
https://www.luogu.org/problem/P2290
prufer板子题
但它是一道紫题也是有它的道理的,就是注意一下坑点
code:(代码很丑,不是我写的(看得我想吐了))
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n;
ll d[151];
ll jie[151];
ll sum;
inline ll calc(ll x){
ll ans=1;
for(int i=2;i<=x;i++){
ans*=i;
}
return ans;
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%lld",&d[i]);
sum+=d[i]-1;
if(d[i]==0&&n!=1){
printf("0");
return 0;
}
jie[i]=calc(d[i]-1);
}
if(sum!=n-2){
printf("0");
return 0;
}
ll ans=1;
int j=1;
for(int i=1;i<=n-2;i++){
ans*=i;
if(j>n)continue;
if(ans%jie[j]==0){
ans/=jie[j];
j++;
}
}
printf("%lld",ans);
return 0;
}
标签:151,jie,训练,int,ll,long,之二,计数,ans 来源: https://www.cnblogs.com/wzxbeliever/p/11697503.html