UVa 1645 Count(**)

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   os   for   2014   div   

題目大意:輸入n,統計有多少個n個結點的有根樹,使得每個深度中所有結點的子結點數相同。結果模1000000007。

思路:根據題意,每個結點的每個子樹都是相同的。所以n結果為n-1的所有約數的結果加起來。

:

代碼如下:

 

 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 }

 

UVa 1645 Count(**)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.