다이나믹 프로그래밍(DP) 의 기초문제


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import java.util.Scanner;
 
import javax.swing.plaf.synth.SynthSeparatorUI;
 
public class Main {
    static int z=0;
    static int o=0;
    static int[] a = { 00 };
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
        int T = sc.nextInt();
        for (int i = 0; i < T; i++) {
            int x = sc.nextInt();
            while (x > 40 || x<0) {
                x = sc.nextInt();
            }
            fibonacci(x);
            System.out.println(z + " " + o);
            z=0;
            o=0;
        } // for end
 
    }
 
    public static int fibonacci(int n) {
        if (n == 0) {
            z++;
            return 0;
        } else if (n == 1) {
            o++;
            return 1;
        } else {
            return fibonacci(n - 1+ fibonacci(n - 2);
        }
    }
 
 
 
}
 
cs


'알고리즘' 카테고리의 다른 글

[2579번] 계단 오르기  (0) 2017.12.12
[1463번] 1로 만들기  (0) 2017.12.12
[1965번] 상자넣기  (0) 2017.12.05
[1149번] RGB거리  (0) 2017.12.05
[11404번] 플로이드  (0) 2017.12.05

+ Recent posts