• 문제 링크
10752번: Cow Hopscotch
Just like humans enjoy playing the game of Hopscotch, Farmer John's cows have invented a variant of the game for themselves to play. Being played by clumsy animals weighing nearly a ton, Cow Hopscotch almost always ends in disaster, but this has surprising
www.acmicpc.net
• 풀이 코드
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st = new StringTokenizer(br.readLine());
int r = Integer.parseInt(st.nextToken()), c = Integer.parseInt(st.nextToken());
char[][] mat = new char[r][c];
for (int i = 0; i < r; i++) mat[i] = br.readLine().toCharArray();
int[][] cache = new int[r][c];
cache[0][0] = 1;
for (int i = 1; i < r; i++)
for (int j = 1; j < c; j++)
for (int k = 0; k < i; k++)
for (int l = 0; l < j; l++) if (mat[i][j] != mat[k][l]) cache[i][j] += cache[k][l];
bw.write(String.valueOf(cache[r - 1][c - 1]));
bw.flush();
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 15841 Virus Outbreak - Dynamic Programming / Java (0) | 2024.01.21 |
---|---|
[백준] 6221 The Bale Tower - Dynamic Programming / Java (0) | 2024.01.20 |
[백준] 11867 박스 나누기 게임 - Dynamic Programming / Java (0) | 2024.01.18 |
[백준] 4811 알약 - Dynamic Programming / Java (0) | 2024.01.17 |
[백준] 25632 소수 부르기 게임 - Greedy / Java (0) | 2024.01.16 |
댓글