728x90
https://www.acmicpc.net/problem/2133
n=2 -> 3
n=4 -> 11
n=6 -> 41
점화식 : arr[i]= arr[i-1]*4 - arr[i-2]
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int num = Integer.parseInt(br.readLine());
int[] arr = new int[30];
arr[0] = 1; // 1
arr[1] = 3; // 2
arr[2] = 11; // 4
if (num % 2 == 0) {
for (int i = 3; i <= num / 2; i++) {
arr[i] = arr[i-1] *4 - arr[i-2];
}
System.out.println(arr[num/2]);
}
else {
System.out.println(0);
}
}
}
'Java' 카테고리의 다른 글
[백준 1309] 동물원 (JAVA) (0) | 2023.02.08 |
---|---|
[백준 2293] 동전1 (JAVA) (0) | 2023.02.07 |
[백준 1439] 뒤집기 (JAVA) (0) | 2023.02.04 |
[백준 1202] 보석도둑 (JAVA) (0) | 2023.02.03 |
[백준 7576] 토마토 풀이 (JAVA) (0) | 2023.02.03 |