Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. package sdk.backjun.dp;
  2.  
  3. import java.util.Scanner;
  4.  
  5. /**
  6. * 백준, 11048, 이동하기
  7. * 다이나믹 프로그래밍
  8. *
  9. * @author whitebeardk
  10. *
  11. */
  12. public class Problem11048 {
  13.  
  14. public static void main(String[] args) {
  15.  
  16. Scanner sc = new Scanner(System.in);
  17. int N = sc.nextInt(); // 미로의 크기 N
  18. int M = sc.nextInt(); // 미로의 크기 M
  19.  
  20. int[][] maps = new int[N+1][M+1];
  21. int[][] dp = new int[N+1][M+1];
  22.  
  23. for(int x = 1; x <= N; x++) {
  24. for(int y = 1; y <= M; y++) {
  25. maps[x][y] = sc.nextInt();
  26. }
  27. }
  28.  
  29. sc.close();
  30.  
  31. for(int x = 1; x <= N; x++) {
  32. for(int y = 1; y <= M; y++) {
  33. // 좌측, 상단의 DP값 중 더 큰값에 현재의 사탕개수를 더하여 DP값에 저장
  34. dp[x][y] = Math.max(dp[x-1][y], dp[x][y-1]) + maps[x][y];
  35. }
  36. }
  37.  
  38. System.out.println(dp[N][M]);
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement