Skip to content

Commit 9e6f398

Browse files
committedMay 19, 2024
Merge branch 'week6'
2 parents bce2da9 + 259db6a commit 9e6f398

7 files changed

+227
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
6+
public static void main(String[] args) throws IOException {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
StringTokenizer st = new StringTokenizer(br.readLine());
9+
int N = Integer.parseInt(st.nextToken());
10+
int M = Integer.parseInt(st.nextToken());
11+
int[][] arr = new int[N + 1][N + 1];
12+
for (int i = 1; i <= N; i++) {
13+
st = new StringTokenizer(br.readLine());
14+
for (int j = 1; j <= N; j++) {
15+
arr[i][j] = Integer.parseInt(st.nextToken());
16+
}
17+
}
18+
int[][] d = new int[N + 1][N + 1];
19+
for (int i = 1; i <= N; i++) {
20+
for (int j = 1; j <= N; j++) {
21+
d[i][j] = d[i - 1][j] + d[i][j - 1] - d[i - 1][j - 1] + arr[i][j];
22+
}
23+
}
24+
int x1, y1, x2, y2;
25+
StringBuilder sb = new StringBuilder();
26+
for (int i = 0; i < M; i++) {
27+
st = new StringTokenizer(br.readLine());
28+
x1 = Integer.parseInt(st.nextToken());
29+
y1 = Integer.parseInt(st.nextToken());
30+
x2 = Integer.parseInt(st.nextToken());
31+
y2 = Integer.parseInt(st.nextToken());
32+
sb.append(d[x2][y2] - d[x2][y1 - 1] - d[x1 - 1][y2] + d[x1 - 1][y1 - 1]).append('\n');
33+
}
34+
System.out.print(sb);
35+
}
36+
}

‎week6/BOJ_1495(기타리스트).java

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
6+
public static void main(String[] args) throws IOException {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
StringTokenizer st = new StringTokenizer(br.readLine());
9+
int N = Integer.parseInt(st.nextToken());
10+
int S = Integer.parseInt(st.nextToken());
11+
int M = Integer.parseInt(st.nextToken());
12+
int[] volume = new int[N + 1];
13+
st = new StringTokenizer(br.readLine());
14+
for (int i = 1; i <= N; i++) {
15+
volume[i] = Integer.parseInt(st.nextToken());
16+
}
17+
boolean[][] d = new boolean[N + 1][M + 1];
18+
d[0][S] = true;
19+
for (int i = 1; i <= N; i++) {
20+
for (int vol = 0; vol <= M; vol++) {
21+
// 이전에 곡에서 연주 가능한 볼륨일 경우
22+
if (d[i - 1][vol]) {
23+
if (vol + volume[i] <= M) {
24+
d[i][vol + volume[i]] = true;
25+
}
26+
if (vol - volume[i] >= 0) {
27+
d[i][vol - volume[i]] = true;
28+
}
29+
}
30+
}
31+
}
32+
int answer = -1;
33+
for (int i = M; i >= 0; i--) {
34+
if (d[N][i]) {
35+
answer = i;
36+
break;
37+
}
38+
}
39+
System.out.println(answer);
40+
}
41+
}

‎week6/BOJ_1535(안녕).java

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
6+
public static void main(String[] args) throws IOException {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
int N = Integer.parseInt(br.readLine());
9+
int[] hp = new int[N + 1];
10+
int[] happy = new int[N + 1];
11+
int[][] d = new int[N + 1][101];
12+
StringTokenizer st1 = new StringTokenizer(br.readLine());
13+
StringTokenizer st2 = new StringTokenizer(br.readLine());
14+
for (int i = 1; i <= N; i++) {
15+
hp[i] = Integer.parseInt(st1.nextToken());
16+
happy[i] = Integer.parseInt(st2.nextToken());
17+
}
18+
for (int i = 1; i <= N; i++) {
19+
for (int j = 1; j <= 100; j++) {
20+
if (j - hp[i] > 0) {
21+
d[i][j] = Math.max(d[i - 1][j], d[i - 1][j - hp[i]] + happy[i]);
22+
} else {
23+
d[i][j] = d[i - 1][j];
24+
}
25+
}
26+
}
27+
System.out.println(d[N][100]);
28+
}
29+
}

‎week6/BOJ_1890(점프).java

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
6+
public static void main(String[] args) throws IOException {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
int N = Integer.parseInt(br.readLine());
9+
int[][] board = new int[N][N];
10+
for (int i = 0; i < N; i++) {
11+
StringTokenizer st = new StringTokenizer(br.readLine());
12+
for (int j = 0; j < N; j++) {
13+
board[i][j] = Integer.parseInt(st.nextToken());
14+
}
15+
}
16+
long[][] d = new long[N][N];
17+
d[0][0] = 1;
18+
for (int i = 0; i < N; i++) {
19+
for (int j = 0; j < N; j++) {
20+
int jump = board[i][j];
21+
if (jump == 0) {
22+
continue;
23+
}
24+
if (j + jump < N) {
25+
d[i][j + jump] += d[i][j];
26+
}
27+
if (i + jump < N) {
28+
d[i + jump][j] += d[i][j];
29+
}
30+
}
31+
}
32+
System.out.println(d[N - 1][N - 1]);
33+
}
34+
}

‎week6/BOJ_1932(정수 삼각형).java

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
6+
public static void main(String[] args) throws IOException {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
int n = Integer.parseInt(br.readLine());
9+
int[][] arr = new int[n+1][n+1];
10+
for(int i=1; i<=n; i++) {
11+
StringTokenizer st = new StringTokenizer(br.readLine());
12+
for(int j=1; j<=i; j++) {
13+
arr[i][j] = Integer.parseInt(st.nextToken());
14+
}
15+
}
16+
int[][] d = new int[n+1][n+1];
17+
for(int i=1; i<=n; i++) {
18+
for(int j=1; j<=i; j++) {
19+
d[i][j] = Math.max(d[i-1][j-1], d[i-1][j]) + arr[i][j];
20+
}
21+
}
22+
int answer = arr[1][1];
23+
for(int i=1; i<=n; i++) {
24+
answer = Math.max(answer, d[n][i]);
25+
}
26+
System.out.println(answer);
27+
}
28+
}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
6+
public static void main(String[] args) throws IOException {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
StringTokenizer st = new StringTokenizer(br.readLine());
9+
int D = Integer.parseInt(st.nextToken());
10+
int K = Integer.parseInt(st.nextToken());
11+
for(int i=1; i<=K; i++) {
12+
int[] d = new int[D+1];
13+
d[1] = i;
14+
for(int j=i; j<=K; j++) {
15+
d[2] = j;
16+
for(int k=3; k<=D; k++) {
17+
d[k] = d[k-2] + d[k-1];
18+
}
19+
if(d[D] == K) {
20+
System.out.println(d[1]);
21+
System.out.println(d[2]);
22+
return;
23+
}
24+
}
25+
}
26+
}
27+
}

‎week6/BOJ_9465(스티커).java

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
6+
public static void main(String[] args) throws IOException {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
int T = Integer.parseInt(br.readLine());
9+
for(int tc=0; tc<T; tc++) {
10+
int N = Integer.parseInt(br.readLine());
11+
int[][] sticker = new int[3][N+1];
12+
for(int i=0; i<2; i++) {
13+
StringTokenizer st = new StringTokenizer(br.readLine());
14+
for(int j=0; j<N; j++) {
15+
sticker[i][j] = Integer.parseInt(st.nextToken());
16+
}
17+
}
18+
// d[0][i] = 윗줄 스티커만 뜯는 경우
19+
// d[1][i] = 아랫줄 스티커만 뜯는 경우
20+
// d[2][i] = 스티커를 떼지 않는 경우
21+
int[][] d = new int[3][N+1];
22+
d[0][0] = sticker[0][0];
23+
d[1][0] = sticker[1][0];
24+
for(int i=1; i<=N; i++) {
25+
d[0][i] = Math.max(d[1][i-1], d[2][i-1]) + sticker[0][i];
26+
d[1][i] = Math.max(d[0][i-1], d[2][i-1]) + sticker[1][i];
27+
d[2][i] = Math.max(d[0][i-1], Math.max(d[1][i-1], d[2][i-1]));
28+
}
29+
System.out.println(Math.max(d[0][N], d[1][N]));
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)
Please sign in to comment.