zoukankan      html  css  js  c++  java
  • Luogu2290 [HNOI2004]树的计数 (组合计数,prufer编码)

    这不prufer编码吗,防爆long long就行了啊

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #define R(a,b,c) for(register int  a = (b); a <= (c); ++ a)
    #define nR(a,b,c) for(register int  a = (b); a >= (c); -- a)
    #define Max(a,b) ((a) > (b) ? (a) : (b))
    #define Min(a,b) ((a) < (b) ? (a) : (b))
    #define Fill(a,b) memset(a, b, sizeof(a))
    #define Abs(a) ((a) < 0 ? -(a) : (a))
    #define Swap(a,b) a^=b^=a^=b
    #define ll long long
    
    #define ON_DEBUG
    
    #ifdef ON_DEBUG
    
    #define D_e_Line printf("
    
    ----------
    
    ")
    #define D_e(x)  cout << #x << " = " << x << endl
    #define Pause() system("pause")
    #define FileOpen() freopen("in.txt","r",stdin);
    
    #else
    
    #define D_e_Line ;
    #define D_e(x)  ;
    #define Pause() ;
    #define FileOpen() ;
    
    #endif
    
    struct ios{
        template<typename ATP>ios& operator >> (ATP &x){
            x = 0; int f = 1; char c;
            for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-')  f = -1;
            while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
            x*= f;
            return *this;
        }
    }io;
    using namespace std;
    
    const int N = 157;
    
    #define int long long
    int C[N][N];
    inline void Prepare(int &n){
    	R(i,0,n){
    		C[i][0] = 1;
    		R(j,1,i){
    			C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
    		}
    	}
    }
    int d[N];
    #undef int
    int main(){
    #define int long long
    	int n;
    	io >> n;
    	int sum = 0;
    	if(n == 1){
    		io >> d[1];
    		if(!d[1]){
    			printf("1");
    		}
    		else{
    			printf("0");
    		}
    		return 0;
    	}
    	R(i,1,n){
    		io >> d[i];
    		if(!d[i]){
    			printf("0");
    			return 0;
    		}
    		--d[i];
    		sum += d[i];
    	}
    	
    	if(sum != n - 2){
    		printf("0");
    		return 0;
    	}
    	
    	Prepare(n);
    	
    	sum = 0;
    	int ans = 1;
    	R(i,1,n){
    		ans *= C[n - 2 - sum][d[i]];
    		sum += d[i];
    	}
    	
    	printf("%lld", ans);
    	
    	return 0;
    }
    

  • 相关阅读:
    Java Excel导入
    Git在Eclipse中忽略文件提交
    Git客户端安装(仅限windows用户)
    Java输出流文件下载
    Centos6.3源码安装Mysql-5.5.34
    Centos6.3安装Mongodb2.2.4
    Jacob操作Word各格式转换参数
    sublime text3使用小结
    获得select下拉框的值
    sublim text3 配置
  • 原文地址:https://www.cnblogs.com/bingoyes/p/11258439.html
Copyright © 2011-2022 走看看