HDU 4472 count

Source: Internet
Author: User

Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4472


Give you n nodes to form a tree. Each node on each layer of the tree must have the same son tree.

Idea: apart from the root node, we divide n-1 nodes into J groups, that is, we regard this tree as a symmetric tree with the same number of nodes in each group. So DP [I] = sum (DP [J]), (1 <= j <= I-1 & (I-1) % J = 0)


Code:

# Include <cstdio> # include <iostream> # include <cstring> # include <cmath> using namespace STD; const int mod = 1000000007; int DP [1010]; int main () {DP [1] = 1; DP [2] = 1; DP [3] = 2; DP [4] = 3; for (INT I = 5; I <= 1000; I ++) {for (Int J = 1; j + 1 <= I; j ++) {If (I-1) % J = 0) {DP [I] + = DP [J]; DP [I] = DP [I] % mod ;}} int N; int Kase = 0; while (scanf ("% d", & n) = 1) {printf ("case % d: % d \ n", ++ Kase, DP [N]);} return 0 ;}


HDU 4472 count

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.