[백준]점프1890_java

이민재·2022년 8월 26일
0
package algo.Baek;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main_1890_0826 {
	static int N, Map[][], cnt;
	static int delta[][] = {{0,1},{1,0}};
	static long isCheck[][];
	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = null;

		N = Integer.parseInt(br.readLine());
		cnt = 0;
		
		Map = new int[N][N];
		isCheck = new long[N][N];
		
		for(int i = 0 ; i < N;i++) {
			st = new StringTokenizer(br.readLine());
			for (int j = 0; j < N; j++) {
				Map[i][j] = Integer.parseInt(st.nextToken());
			}
		}
		isCheck[0][0] = 1;
		
		for(int i = 0 ; i < N;i++) {
			for (int j = 0; j < N; j++) {
				
				if(isCheck[i][j] == 0 || Map[i][j] == 0) continue;
				
				for (int k = 0; k < 2; k++) {
					int nextX = i + delta[k][0]*Map[i][j];
					int nextY = j + delta[k][1]*Map[i][j];
					
					if(nextX >= N || nextY >= N) continue;
					
					isCheck[nextX][nextY] += isCheck[i][j];
					
				}
			}
		}

		System.out.println(isCheck[N-1][N-1]);
	}
	
}
profile
초보 개발자

0개의 댓글