import java.util.Scanner; public class Main { static int n; static int result = 0; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { n = scanner.nextInt(); int len = 0; getResult(len); System.out.println(result); result = 0; } } private static void getResult(int len) { if (len == n) { result++; return; } if (len > n) { return; } if (len + 1 <= n) { getResult(len + 1); } if (len + 2 <= n) { getResult(len + 2); } } }
原文地址:http://blog.csdn.net/u011506951/article/details/27204119