Created
June 26, 2017 13:56
-
-
Save developer-sdk/2732be43bfaab696e91119766296972b to your computer and use it in GitHub Desktop.
백준, 1890, 점프
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package sdk.backjun.dp; | |
| import java.util.Scanner; | |
| /** | |
| * 백준, 1890, 점프 | |
| * 다이나믹 프로그래밍 | |
| * | |
| * @author whitebeardk | |
| * | |
| */ | |
| public class Problem1890 { | |
| public static void main(String[] args) { | |
| Scanner sc = new Scanner(System.in); | |
| int N = sc.nextInt(); | |
| int[][] maps = new int[N][N]; | |
| for (int i = 0; i < N; i++) { | |
| for (int j = 0; j < N; j++) { | |
| maps[i][j] = sc.nextInt(); | |
| } | |
| } | |
| sc.close(); | |
| // 값이 커질 수 있으므로 long 형으로 초기화 | |
| long[][] dp = new long[N][N]; | |
| dp[0][0] = 1; | |
| for (int x = 0; x < N; x++) { | |
| for (int y = 0; y < N; y++) { | |
| int move = maps[x][y]; | |
| if (dp[x][y] == 0 || move == 0) | |
| continue; | |
| if (x + move < N) { | |
| dp[x + move][y] += dp[x][y]; | |
| } | |
| if (y + move < N) { | |
| dp[x][y + move] += dp[x][y]; | |
| } | |
| } | |
| } | |
| System.out.println(dp[N - 1][N - 1]); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment