-
Notifications
You must be signed in to change notification settings - Fork 0
/
prefix2D.c
70 lines (44 loc) · 1.08 KB
/
prefix2D.c
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<stdio.h>
void psa(int Row, int Col, int arr[Row][Col]) {
int psa[Row][Col];
psa[0][0] = arr[0][0];
for(int i = 1; i < Row; i++)
psa[i][0] = psa[i - 1][0] + arr[i][0];
for(int j = 1; j < Col; j++)
psa[0][j] = psa[0][j - 1] + arr[0][j];
for(int i = 1; i < Row; i ++)
for(int j = 1; j < Col; j++) {
psa[i][j] = psa[i - 1][j] + psa[i][j - 1] - psa[i - 1][j - 1] + arr[i][j];
}
for(int i = 0; i < Row; i++)
for(int j = 0; j < Col; j++) {
printf("%d", psa[i][j]);
if(j != Col - 1) printf(" ");
else printf("\n");
}
}
int main() {
int Row, Col;
scanf("%d %d", &Row, &Col);
int arr[Row][Col];
for(int i = 0; i < Row; i++)
for(int j = 0; j < Col; j++)
scanf("%d", &arr[i][j]);
psa(Row, Col, arr);
return 0;
}
/*
r, col
r = 0, j = 0 - col
if j == 0
psa[0][j] = dt[0][j]
else
psa[0][j] == psa[0][j - 1] + dt[0][j]
1 2 3 4
5 6 7 8
9 0 1 2
3 4 5 6
1 3 6 10
6 14 24 36
15 23 34 46
*/