-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
480eb77
commit 08a24ba
Showing
3 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package BOJ.silver2; | ||
|
||
import java.util.*; | ||
import java.io.*; | ||
|
||
public class BOJ_11048 { | ||
|
||
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 n = Integer.parseInt(st.nextToken()); | ||
int m = Integer.parseInt(st.nextToken()); | ||
|
||
int[][] ll = new int[n][m]; | ||
int[][] dp = new int[n][m]; | ||
|
||
//초기값 저장 | ||
for(int i = 0; i<n; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
for(int j = 0; j<m; j++) { | ||
ll[i][j] = Integer.parseInt(st.nextToken()); | ||
} | ||
} | ||
|
||
//초기화 | ||
dp[0][0] = ll[0][0]; | ||
|
||
for(int i = 1; i<n; i++) { | ||
dp[i][0] = dp[i-1][0] + ll[i][0]; | ||
} | ||
|
||
for(int i = 1; i<m; i++) { | ||
dp[0][i] = dp[0][i-1] + ll[0][i]; | ||
} | ||
|
||
for(int i = 1; i<n; i++) { | ||
for(int j = 1; j<m; j++) { | ||
dp[i][j] = ll[i][j] + Math.max(Math.max(dp[i-1][j], dp[i][j-1]), dp[i-1][j-1]); | ||
} | ||
} | ||
|
||
bw.write(dp[n-1][m-1] + "\n"); | ||
bw.flush(); | ||
br.close(); | ||
bw.close(); | ||
|
||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package BOJ.silver2; | ||
|
||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class BOJ_1912 { | ||
|
||
public static void main(String[] args) throws IOException{ | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); | ||
|
||
int num = Integer.parseInt(br.readLine()); | ||
int[] dp = new int[num]; | ||
int[] ll = new int[num]; | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
||
for(int i = 0; i<num; i++) { | ||
ll[i] = Integer.parseInt(st.nextToken()); | ||
} | ||
|
||
dp[0] = ll[0]; //초기화 | ||
|
||
for(int i = 1; i<num;i++) { | ||
dp[i] = ll[i] + Math.max(0, dp[i-1]); | ||
} | ||
|
||
int max = Integer.MIN_VALUE; | ||
|
||
for(int i = 0; i<num; i++) { | ||
max = Math.max(max, dp[i]); //dp[i] 수열에서 최소값 구하기 | ||
} | ||
|
||
bw.write(max + "\n"); | ||
bw.flush(); | ||
bw.close(); | ||
br.close(); | ||
} | ||
} |
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