[HDOJ5326]Work

來源:互聯網
上載者:User

標籤:

題目連結:http://acm.hdu.edu.cn/showproblem.php?pid=5326

 

找一連串的下屬,可以用遞迴。首先存好直接關係,接著暴搜打表再查即可。

 

 1 #include <cstdio> 2 #include <cstdlib> 3 #include <cstring> 4 #include <algorithm> 5 #include <iostream> 6 #include <cmath> 7 #include <cctype> 8 #include <queue> 9 #include <map>10 #include <set>11 #include <stack>12 #include <list>13 #include <vector>14 15 using namespace std;16 17 const int maxn = 1010;18 int n, k, x, y;19 int par[maxn];20 int G[maxn][maxn];21 22 void dfs(int x, int y) {23     for(int i = 1; i <= n; i++) {24         if(G[y][i]) {25             par[x]++;26             dfs(x, i);27         }28     }29 }30 31 int main() {32     // freopen("in", "r", stdin);33     while(~scanf("%d %d", &n, &k)) {34         memset(par, 0, sizeof(par));35         memset(G, 0, sizeof(G));36         int ans = 0;37         for(int i = 0; i < n - 1; i++) {38             scanf("%d %d", &x, &y);39             G[x][y] = 1;40         }41         for(int i = 1; i <= n; i++) {42             for(int j = 1; j <= n; j++) {43                 if(G[i][j]) {44                     par[i]++;45                     dfs(i, j);46                 }47             }48         }49         for(int i = 1; i <= n; i++) {50             if(par[i] == k) {51                 ans++;52             }53         }54         printf("%d\n", ans);55     }56     return 0;57 }

 

[HDOJ5326]Work

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.