解题思路:
注意事项:
参考代码:
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] from=new int[n+1]; for (int i = 1; i <=n; i++) { from[i]=sc.nextInt(); } int max=0; for (int i = 1; i <= n; i++) { if(gd(from,i,from[i])>max){ max=gd(from,i,from[i]); } } System.out.println(max); } private static int gd(int[] from,int des,int start) { if(from[des]==0){ return 1; } return gd(from,start,from[start])+1; } }
0.0分
0 人评分
C二级辅导-分段函数 (C语言代码)浏览:567 |
C二级辅导-阶乘数列 (C语言代码)浏览:618 |
简单的a+b (C语言代码)浏览:649 |
妹子杀手的故事 (C语言代码)浏览:692 |
C语言训练-自由落体问题 (C语言代码)浏览:1744 |
C语言程序设计教程(第三版)课后习题9.1 (Java代码)浏览:471 |
C语言程序设计教程(第三版)课后习题7.1 (C语言代码)浏览:743 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:619 |
人见人爱A+B (C语言代码)浏览:630 |
上车人数 (C语言代码)浏览:783 |