IT 정보/알고리즘(백준, BOJ)
[백준-BOJ] 2302
Dalyoung
2021. 2. 6. 22:13
반응형
2302번: 극장 좌석
주어진 조건을 만족하면서 사람들이 좌석에 앉을 수 있는 방법의 가짓수를 출력한다. 방법의 가짓수는 2,000,000,000을 넘지 않는다. (2,000,000,000 < 231-1)
www.acmicpc.net
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
Main m = new Main();
m.doit();
}
public void doit() throws IOException{
// System.setIn(new FileInputStream("input.txt"));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
int M = Integer.parseInt(br.readLine());
int [] vip = new int[M];
for(int i = 0; i < M; i++){
vip[i] = Integer.parseInt(br.readLine());
}
int [] fibo = new int[N + 1];
fibo[0] = 1; fibo[1] = 1;
for(int i = 2; i <= N; i++){
fibo[i] = fibo[i-1] + fibo[i-2];
}
// System.out.println(Arrays.toString(fibo));
int index = 0;
int ret = 1;
for(int i = 0; i < vip.length; i++){
int f = vip[i] - index - 1;
if(f >= 0){
ret = ret * fibo[f];
}
index = vip[i];
}
if(index < N){
int f = N - index;
ret = ret * fibo[f];
}
System.out.println(ret);
br.close();
}
}
반응형