🌐 AI搜索 & 代理 主页
Skip to content

Commit 6fe1b22

Browse files
committed
Learning DP
0 parents  commit 6fe1b22

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/Fibonacci.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import java.io.*;
2+
public class Fibonacci {
3+
public static void main(String[] args)throws IOException{
4+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
5+
6+
int q = Integer.parseInt(br.readLine());
7+
long[] f = new long[q]; // DON'T TAKE INTS ;)
8+
f[0] = 0;
9+
f[1] = 1;
10+
11+
for(int i=2; i<q; i++){
12+
f[i] = f[i-1] + f[i-2];
13+
}
14+
15+
System.out.println(f[q-1]);
16+
17+
}
18+
}

0 commit comments

Comments
 (0)