Prufer coding exercises, this code is related to the generation count of the tree.
Recommend this blog: http://www.cnblogs.com/zhj5chengfeng/archive/2013/08/23/3278557.html Introduction very comprehensive + vivid image
After the Prufer, the problem will be calculated with a combination of math and high precision.
#include <cstdlib> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm > #include <fstream> #include <iostream> #define REP (i, L, R) for (int. i=l; i<=r; i++) #define DOWN (i, L, R) for (int i=l; i>=r; i--) #define N 12345#define MAX 1<<30#define Q 1000000using namespace Std;int read () {int x=0, F = 1; Char Ch=getchar (); while (ch< ' 0 ' | | ch> ' 9 ') {if (ch== '-') f=-1; Ch=getchar ();} while (ch>= ' 0 ' && ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} return x*f;} int n, D[n], K, S, M[n], l;void Mult (int x) {Rep (I, 1, l) m[i]*=x;rep (I, 1, l) m[i+1]+=m[i]/q, M[i]%=q;while (m[l+1]) l++, m[l+1]+=m[l]/q, M[l]%=q;} void Div (int x) {int A=0;down (i, L, 1) a=a*q+m[i], m[i]=a/x, A%=x;while (m[l]==0 && l>1) l--;} int main () {n=read (); Rep (i, 1, N) d[i]=read (); Rep (i, 1, N) if (d[i]!=-1) k++, s+=d[i]-1;if (s>n-2) printf ("0"); else{m[ L=1] = 1;rep (i, 1, n-2) Mult (i); Rep (i, 1, n-2-s) Div (i); Rep (i, 1, n-2-s) Mult (N-K); Rep (I, 1,N) if (D[i]!=-1) Rep (j, 1, D[i]-1) Div (j);p rintf ("%d", M[l]);d Own (I, L-1, 1) if (m[i]>=100000) printf ("%d", m[i]); else if (m[i]>=10000) printf ("0%d", M[i]), else if (m[i]>=1000) printf ("00%d", M[i]), else if (m[i]>=100) printf ("0% D ", M[i]), else if (m[i]>=10) printf (" 0000%d ", M[i]), Else printf (" 00000%d ", M[i]);} return 0;}
BZOJ-1005 's troubles