UV 1645 count (**)

Source: Internet
Author: User
Tags cmath

Enter n to calculate the number of root trees of N nodes, so that the number of subknots of all nodes in each depth is the same. Result modulus 1000000007.

Idea: Based on the meaning of the question, each subtree at each node is the same. Therefore, the N result is n-1 sum of all the n-grams.

:

The Code is as follows:

 

 1 #include <iostream> 2 #include <sstream> 3 #include <cstdio> 4 #include <cstring> 5 #include <cmath> 6 #include <string> 7 #include <vector> 8 #include <set> 9 #include <cctype>10 #include <algorithm>11 #include <cmath>12 #include <deque>13 #include <queue>14 #include <map>15 #include <stack>16 #include <list>17 #include <iomanip>18 19 using namespace std;20 21 #define INF 0x7fffffff22 #define maxn 101023 typedef long long ll;24 const int MOD = 1000000007;25 26 ll ans[maxn];27 28 void init()29 {30     memset(ans, 0, sizeof(ans));31     ans[1] = 1;32     for(int i = 2; i < maxn; i++)33     {34         for(int j = 1; j < i; j++)35         {36             if((i-1)%j) continue;37             ans[i] += ans[j];38             ans[i] %= MOD;39         }40     }41 }42 43 int main()44 {45     init();46     int n, kase = 0;47     while(cin >> n)48     {49         cout << "Case " << ++kase << ": "<< ans[n] << endl;50     }51     return 0;52 }

 

UV 1645 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.