import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.StreamTokenizer; public class Main { public static void main(String[] args) throws IOException { StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); while(true){ st.nextToken(); int n = (int) st.nval; if(n =55){ break; } System.out.println(f(n));; } } public static Integer[] cache = new Integer[60]; public static int f(int n){ if(n<=4){ cache[n] = n; return n; } if(cache[n]!=null){ return cache[n]; } cache[n] = f(n-1)+f(n-3); return cache[n]; } }
把Scanner替换为StreamTokenizer,运行时间会降低不少
0.0分
1 人评分