Created
May 24, 2016 23:53
-
-
Save jojoldu/bd6459d429d85ca59205503500476908 to your computer and use it in GitHub Desktop.
boj-11048
This file contains 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
/** | |
* Created by jojoldu@zuminternet.com on 2016-05-24. | |
*/ | |
import java.util.Scanner; | |
/** | |
* https://www.acmicpc.net/problem/11048 | |
*/ | |
public class Main { | |
private static int[][] maze; | |
private static int[][] maxList; | |
private static int height; | |
private static int width; | |
public static void main(String[] args) { | |
Scanner sc = new Scanner(System.in); | |
height = sc.nextInt(); | |
width = sc.nextInt(); | |
maze = new int[height+1][width+1]; | |
maxList = new int[height+1][width+1]; | |
for(int i=1;i<=height;i++){ | |
for(int j=1;j<=width;j++){ | |
maze[i][j] = sc.nextInt(); | |
} | |
} | |
System.out.println(move(height,width)); | |
} | |
private static int move(int i, int j){ | |
if(i == 1 && j == 1){ | |
return maze[i][j]; | |
} | |
if(i < 1 || j < 1){ | |
return 0; | |
} | |
if(maxList[i][j] > 0){ | |
return maxList[i][j]; | |
} | |
maxList[i][j] = move(i-1, j) + maze[i][j]; | |
int other = move(i, j-1) + maze[i][j]; | |
if(maxList[i][j] < other){ | |
maxList[i][j] = other; | |
} | |
return maxList[i][j]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
재귀로 풀었을 경우