Skip to content

Commit

Permalink
2024-05-23 구간합구하기5
Browse files Browse the repository at this point in the history
  • Loading branch information
dhlee777 committed May 23, 2024
1 parent 8fbdbb3 commit fd725c5
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions dhlee777/dp/구간합구하기5.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include<iostream>
using namespace std;
int dp[1025][1025];
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int size, cnt, start_row, start_col, end_row, end_col,temp;
cin >> size >> cnt;

for (int i = 1; i <=size; i++) {
for (int j = 1; j <=size; j++) {
cin >> temp;
dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + temp;
}
}
for (int k = 0; k < cnt; k++) {
cin >> start_row >> start_col >> end_row >> end_col;
cout << dp[end_row][end_col] - dp[start_row - 1][end_col] - dp[end_row][start_col - 1] + dp[start_row - 1][start_col - 1];
cout << "\n";
}

return 0;
}

0 comments on commit fd725c5

Please sign in to comment.