Hdu4705 tree dp

Source: Internet
Author: User
The number of any three points in the tree is not in a single path. Number of route schemes composed of three points S = C (n, 3) = n * (n-1) * (n-2) 6. using S minus the number of three points in a path is the answer. The enumeration center point is the second point. in its K-th sub-tree, the question is: any three points on the tree are not in a path, and how many of these three points are counted. Number of route schemes composed of three points S = C (n, 3) = n * (n-1) * (n-2) /6. the answer is to subtract the number of three points in one path from S. The enumeration center is used as the second vertex, and a vertex is found on its K-th subtree as the first vertex. in the rest of the nodes that have not been enumerated, find a vertex as the third vertex. Multiply the number. In this way, the problem becomes the subnode of the statistics node, simple tree-like dp. # Include # Include # Include # Include # Include # Pragma comment (linker, "/STACk: 102400000,102400000") using namespace std; vector Tree [100005]; typedef long ll; ll ans, ll n; ll dfs (int k, int fa =-1) {ll sum = 0, son = 0; for (int I = 0; I > N) {for (int I = 1; I <= n; I ++) tree [I]. clear (); for (int I = 1; I

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.