-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2167.cpp
More file actions
47 lines (41 loc) · 728 Bytes
/
2167.cpp
File metadata and controls
47 lines (41 loc) · 728 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// 2167. 2차원 배열의 합
// 2019.05.19
// 다이나믹 프로그래밍
#include<iostream>
using namespace std;
int d[301][301];
int sum[301][301]; //sum[i][j] : 1,1부터 i,j까지의 합
int main()
{
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) // 행
{
for (int j = 1; j <= m; j++) // 열
{
cin >> d[i][j];
}
}
for (int i = 1; i <= n; i++) // 행
{
for (int j = 1; j <= m; j++) // 열
{
sum[i][j] = sum[i][j - 1] + d[i][j];
}
}
int t, i, j, x, y;
cin >> t;
int ans;
while (t > 0)
{
t--;
ans = 0;
cin >> i >> j >> x >> y;
for (int a = i; a <= x; a++)
{
ans += (sum[a][y] - sum[a][j - 1]); // 각 행별로합을 구함
}
cout << ans << endl;
}
return 0;
}