Skip to content

Commit e21449e

Browse files
committed
[DP] baekjoon-11660
1 parent badb2c7 commit e21449e

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

Diff for: README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,5 @@
124124
| # || Problem | Note |
125125
| :-: | :----: | :------------------------------------------------------------------------------------------------------------------ | :------------------------ |
126126
| 01 | | [Baekjoon-1932 정수 삼각형](https://github.com/Seogeurim/Algorithm-practice/blob/master/src/DP/P1932) | |
127-
| 02 | | [Baekjoon-11659 구간 합 구하기 4](https://github.com/Seogeurim/Algorithm-practice/blob/master/src/DP/P11659) | 누적합 |
127+
| 02 | | [Baekjoon-11659 구간 합 구하기 4](https://github.com/Seogeurim/Algorithm-practice/blob/master/src/DP/P11659) | 누적합 |
128+
| 03 | | [Baekjoon-11660 구간 합 구하기 5](https://github.com/Seogeurim/Algorithm-practice/blob/master/src/DP/P11660) | 누적합 |

Diff for: src/DP/P11660/Main.java

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package DP.P11660;
2+
3+
import java.io.BufferedReader;
4+
import java.io.FileInputStream;
5+
import java.io.InputStreamReader;
6+
import java.util.StringTokenizer;
7+
8+
public class Main {
9+
10+
static int N, M;
11+
static int[][] nums;
12+
13+
public static void main(String[] args) throws Exception {
14+
System.setIn(new FileInputStream("src/DP/P11660/input.txt"));
15+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
16+
StringTokenizer st = new StringTokenizer(br.readLine());
17+
18+
N = Integer.parseInt(st.nextToken());
19+
M = Integer.parseInt(st.nextToken());
20+
21+
nums = new int[N][N];
22+
23+
for (int i = 0; i < N; i++) {
24+
st = new StringTokenizer(br.readLine());
25+
for (int j = 0; j < N; j++) {
26+
if (j == 0) nums[i][j] = Integer.parseInt(st.nextToken());
27+
else nums[i][j] = nums[i][j-1] + Integer.parseInt(st.nextToken());
28+
}
29+
}
30+
31+
for (int i = 0; i < M; i++) {
32+
st = new StringTokenizer(br.readLine());
33+
int x1 = Integer.parseInt(st.nextToken()) - 1;
34+
int y1 = Integer.parseInt(st.nextToken()) - 1;
35+
int x2 = Integer.parseInt(st.nextToken()) - 1;
36+
int y2 = Integer.parseInt(st.nextToken()) - 1;
37+
38+
int ans = 0;
39+
for (int j = x1; j <= x2; j++) {
40+
if (y1 > 0) ans += nums[j][y2] - nums[j][y1 - 1];
41+
else ans += nums[j][y2];
42+
}
43+
System.out.println(ans);
44+
}
45+
}
46+
}

Diff for: src/DP/P11660/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## [baekjoon-11660] 구간 합 구하기 5
2+
3+
![image](https://user-images.githubusercontent.com/22045163/90875246-d474f880-e3db-11ea-91bb-25015a1b23fb.png)

Diff for: src/DP/P11660/input.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2 4
2+
1 2
3+
3 4
4+
1 1 1 1
5+
1 2 1 2
6+
2 1 2 1
7+
2 2 2 2

0 commit comments

Comments
 (0)