UVa 1645 (Recursive) Count

Source: Internet
Author: User

Test instructions

How many n nodes have a root tree, which satisfies the same number of child nodes per layer of nodes, and outputs that number divided by the remainder of 1e9+7.

Analysis:

This kind of topic belongs to the kind, looks very high cold, reads the question to be higher cold. Think of N long think not come out, a search problem, lying trough, so SB's question I will not.

To the point, according to test instructions, this tree is about the root node symmetry, symmetry is very good, the root node below the subtree is identical.

So there is the following recursive relationship:

1#include <cstdio>2#include <cmath>3 4 Const intMAXN = +;5 Const intMOD =1000000000+7;6 intANS[MAXN +Ten];7 8 voidInit ()9 {Tenans[1] =1; One      for(inti =2; I <= MAXN; ++i) A     { -         intm =sqrt (i); -          for(intj =1; J <= M; ++J)if((I-1)% J = =0) the         { -             if(J * j = i-1) Ans[i] = (Ans[i] + ans[j])%MOD; -             ElseAns[i] = ((((Ans[i] + ans[j])%mod) + ans[(i-1)/j])%MOD; -         } +     } - } +  A intMain () at { - Init (); -     intKase =0, N; -      while(SCANF ("%d", &n) = =1) -printf"Case %d:%d\n", ++Kase, Ans[n]); -  in     return 0; -}
code June

UVa 1645 (Recursive) 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.