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