计数训练之二

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;
}
posted @ 2019-10-18 11:45  wzx_believer  阅读(94)  评论(0编辑  收藏  举报