UVa 10253 (combined number recursion) Series-parallel Networks

Source: Internet
Author: User

"South of training" on the difficulty of the example is really small, barely able to understand the analysis, its thinking is really unexpected.

Although the topic is very strange, it will eventually be transformed into something that we are familiar with.

After the analysis of God in the book, it will eventually become:

A total of n leaves, the number f (n) of the tree with at least two child nodes per non-leaf node. Final output 2XF (n)

First, you can enumerate the number of leaves in the subtree of the root node, and for a subtree with I leaves, there is a total of f (i),

Set D (I, j) to indicate that each subtrees tree has a maximum of I leaf nodes and a total of J-leaf-node schemes.

The answer is D (n-1, N)

Suppose that there is a subtree of I leaves, because each subtree is independent of each other, so for a subtree of p with I leaves, there are C (f (i) +p-1, p) cases, the whole arrangement of repeating elements.

D (i, j) = Sum{c (f (i) +p-1, p) xd (i-1, J-PXI) | p >= 0 and PXi <= J}

Boundary:

D (i, 0) = d (i, 1) = 1 (i >= 1), D (0, 0) = 1

1#include <cstdio>2 3 Const intMAXN = -;4 Long Longd[ to][ to], f[ to];5 6 Long LongCLong LongNLong Longm)7 {8     Long LongAns =1;9     if(M > n-m) m = n-m;Ten      for(inti =0; I < m; i++) One     { AAns *= N-i; -Ans/= i+1; -     } the     returnans; - } -  - intMain () + { -f[1] =1; +     intn =MAXN; Ad[0][0] =1; at      for(inti =1; I <= N; i++) d[i][0] = d[i][1] =1; -      for(inti =1; I <= N; i++) -     { -          for(intj =2; J <= N; J + +) -         { -              for(intp =0; P * I <= J; p++) inD[I][J] + = C (f[i]+p-1, p) * d[i-1][j-p*i]; -         } tof[i+1] = d[i][i+1]; +     } -  the      while(SCANF ("%d", &n) = =1&&N) *printf"%lld\n", n = =1?1: f[n] *2); $ Panax Notoginseng     return 0; -}
code June

UVa 10253 (combined number recursion) Series-parallel Networks

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.