본문 바로가기

IT/알고리즘

백준 8단계(2775)

반응형
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
43
 
public class Main {
 
    public static int fibo(int floor, int people) {
        //층이 0층이면 그 층의 사람 리턴
        if(floor <= 0return people;
        //사람
        else if(people <= 0return 0;
        
        return fibo(floor - 1, people) + fibo(floor, people - 1);
        //ex floor 2 와 3people라고 가정을 하면
        //fibo(2, 3) = 
        //    fibo(1,3) + fibo(2,2)
        // 즉 fibo(1,3) 또한 = fibo(0,3) + fibo(1,2)
        //이런식으로 계속 내려가면 필요한 값이 나온다, 자세한건 블로그에 사진으로 계시
    
    }
    
    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        
        int n = Integer.parseInt(br.readLine());
        while(n > 0) {
            //몇층
            int floor = Integer.parseInt(br.readLine());
            //사람수
            int people = Integer.parseInt(br.readLine());
            
            int result = fibo(floor, people);
            
            bw.write(String.valueOf(result) + "\n");
            n--;
            
        }
        bw.flush();
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

반응형

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

백준 9단계(1978)  (0) 2019.12.21
백준 8단계(1011)  (0) 2019.12.21
백준 8단계(10250)  (0) 2019.12.15
백준 8단계(2869)  (0) 2019.12.15
백준 8단계(1193)  (0) 2019.12.14