Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
sunjung0120 committed Nov 13, 2024
1 parent 480eb77 commit 08a24ba
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 1 deletion.
51 changes: 51 additions & 0 deletions Ssafy_test/src/BOJ/silver2/BOJ_11048.java
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();

}
}
38 changes: 38 additions & 0 deletions Ssafy_test/src/BOJ/silver2/BOJ_1912.java
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();
}
}
2 changes: 1 addition & 1 deletion Ssafy_test/src/BOJ/silver3/BOJ_11727.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static void main(String[] args) throws IOException{
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

int num = Integer.parseInt(br.readLine());
dp = new int[num+1];
dp = new int[num+2];

dp[1] = 1;
dp[2] = 3;
Expand Down

0 comments on commit 08a24ba

Please sign in to comment.