1211: Count of [HNOI2004] trees
Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1565 Solved: 512
Description
A tree with n nodes, with its nodes of V1, v2, ..., vn, known as the degree of the I node VI as DI, asking how many different trees meet such conditions. Given N,D1, D2, ..., DN, programming needs to output the number of trees that meet the D (vi) =di.
Input
The first line is a positive integer n, which indicates that the tree has n nodes. The second line has n numbers, and the number of I represents Di, which is the degree of the first node of the tree. Where 1<=n<=150, the input data ensures that the tree that satisfies the criteria does not exceed 10^17.
Output
How many trees are available for the output to meet the criteria.
Sample Input
4 2 1 2 1
Sample Output
2
Exercises
Is the weakening version of the obvious annoyance. The practice is basically the same, without high precision is really happy.
Code:
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <algorithm>using namespace STD;#define N#define LL Long LongintN,s,d[n],su[n],ys[n]; LL jc[ -],ans;intIn () {intx=0;CharCh=getchar (); while(ch<' 0 '|| Ch>' 9 ') Ch=getchar (); while(ch>=' 0 '&& ch<=' 9 ') x=x*Ten+ch-' 0 ', Ch=getchar ();returnx;}voidInit () {jc[0]=jc[1]=1; for(intI=2; i<= -; i++) jc[i]=jc[i-1]* (LL) i; for(intI=2; i<=n; i++) {BOOLf=true; for(intj=2; j<=sqrt(i); J + +)if(! (I%J)) {f=false; Break; }if(f) su[++su[0]]=i; }}voidFenjie (intXintY) { for(intI=1; i<=su[0]; i++) {if(x<=1)return; while(! (X%su[i])) Ys[i]+=y,x/=su[i]; }}intMain () {scanf("%d", &n);if(n==1){intX=in ();if(!x) ans=1;Elseans=0;printf("%d\n", ans);return 0; } for(intI=1; i<=n; i++) {d[i]=in ();if(!d[i]) {printf("0\n");return 0; } D[i]--, s+=d[i]; }if(s!=n-2){printf("0\n");return 0; } init (); ans=1;if(n2<= -) Fenjie (jc[n-2],1); for(intI=1; i<=n; i++) Fenjie (jc[d[i]],-1); for(intI=1; i<=su[0]; i++) while(ys[i]--) ans*=su[i];printf("%d\n", ans);return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Count of "Combinatorial math" "Prufer series" "Hnoi 2004" "Bzoj 1211" tree