• 문제 링크
26948번: Plankan
Man vill skapa en längre planka med hjälp av ett antal mindre brädor. Det finns tre olika typer av brädor, som har längden $1$, $2$ respektive $3$ meter. Det finns ett obegränsat antal av varje typ. Det finns $7$ sätt att limma ihop en planka som ä
www.acmicpc.net
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = read();
int[] cache = new int[n];
cache[0] = 1;
cache[1] = 2;
cache[2] = 4;
for (int i = 3; i < n; i++) cache[i] = cache[i - 1] + cache[i - 2] + cache[i - 3];
bw.write(String.valueOf(cache[n - 1]));
bw.flush();
}
private static int read() throws IOException {
int c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 14767 Flow Shop - Dynamic Programming / Java (0) | 2024.02.20 |
---|---|
[백준] 7515 Prehistoric Operating Systems - Dynamic Programming / Java (0) | 2024.02.19 |
[백준] 8582 Park - Dynamic Programming / Java (0) | 2024.02.17 |
[백준] 6092 Strange Towers of Hanoi - Dynamic Programming / Java (0) | 2024.02.16 |
[백준] 25972 도미노 무너트리기 - Greedy / Java (0) | 2024.02.15 |
댓글