BZOJ-1005 The troubles of the Ming

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.