浙大PAT 1004题 1004. Counting Leaves
来源:互联网 发布:软件质量保证计划案例 编辑:程序博客网 时间:2024/06/05 14:35
//求树中每层的叶子节点数#include<stdio.h>int rel[110][110],cnt[110],node;void dfs(int num,int level){ if(cnt[level]==-1) cnt[level]=0; int i,j,judge=0; for(i=1;i<=node;i++){ if(rel[num][i]==1){ judge=1; if(level+1<=node) dfs(i,level+1); } } if(judge==0) cnt[level]++;} int main(){ int i,j,nonleaf,fat,childs,son; for(i=0;i<=100;i++){ cnt[i]=-1; for(j=0;j<=100;j++){ rel[i][j]=0; } } scanf("%d %d",&node,&nonleaf); for(i=1;i<=nonleaf;i++){ scanf("%d %d",&fat,&childs); for(j=1;j<=childs;j++){ scanf("%d",&son); rel[fat][son]=1; } } dfs(1,1); for(i=1;i<=node;i++){ if(cnt[i]>-1&&i==1) printf("%d",cnt[i]); else if(cnt[i]>-1) printf(" %d",cnt[i]); } printf("\n"); return 0;}
- 浙大PAT 1004题 1004. Counting Leaves
- 浙大 PAT Advanced level 1004. Counting Leaves
- 浙大PAT (Advanced Level) Practise 1004. Counting Leaves (30)
- 浙大PAT (Advanced Level) Practise 1004. Counting Leaves (30)
- 浙大PAT 1004 Counting Leaves (简单深搜)
- PAT 1004. Counting Leaves
- 【PAT】1004. Counting Leaves
- pat 1004 Counting Leaves
- pat 1004 counting Leaves
- PAT 1004 Counting Leaves
- PAT 1004 Counting Leaves
- pat 1004 Counting Leaves
- pat 1004 Counting Leaves
- PAT 1004 Counting Leaves
- PAT 1004 Counting Leaves
- PAT 1004 Counting Leaves
- 1004. Counting Leaves (30)-PAT
- pat 1004. Counting Leaves (30)
- android makefile 编译分析及 android.mk分析
- 绑定和分配mmap内核空间(bind_ring)--(七)
- 浙大PAT 1003题 1003. Emergency
- mmap内存映射---(八)
- linux clone()函数
- 浙大PAT 1004题 1004. Counting Leaves
- 浙大PAT 1005题 1005. Spell It Right
- 数据包的读写---(九)
- eclipse执行编译后的类文件抛出Could not find the main class: 异常解决方案之一
- 开源 免费 java CMS - FreeCMS-数据对象-linkClass
- Ext.tree.DWRTreeLoader
- jdk内置工具(一)
- 浙大PAT 1006题 1006. Sign In and Sign Out
- 正则表达式30分钟入门教程