Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 자료구조
- coding
- 너비우선탐색
- 북리뷰
- bfs
- 컴공
- 컴퓨터공학과
- cs
- vector
- 정석학술정보관
- c++
- 코딩
- 구현
- OS
- 개발
- 코테
- Computer science
- 컴공과
- 알고리즘
- 브루트포스
- 백준
- 그래프
- DP
- Operating System
- 오퍼레이팅시스템
- 스택
- 문제풀이
- 오에스
- 정석
- Stack
Archives
- Today
- Total
Little Jay
[C++] 백준 11660번 - 구간 합 구하기5 본문
Prefix Sum문제.
문제에서 정확히 뭘 출력하라고 하는지만 파악하면 쉽게 풀 수 있다.
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int dp[1025][1025];
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n, m;
int x1, y1, x2, y2;
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
cin >> dp[i][j];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
dp[i][j] += dp[i - 1][j];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
dp[i][j] += dp[i][j - 1];
while (m--) {
cin >> x1 >> y1 >> x2 >> y2;
cout << dp[x2][y2] - dp[x1 - 1][y2] - dp[x2][y1 - 1] + dp[x1 - 1][y1 - 1] << endl;
}
return 0;
}
'알고리즘 > BOJ' 카테고리의 다른 글
[C++] 백준 2407 - 조합 (0) | 2022.12.01 |
---|---|
[C++] 백준 16964번 - DFS 스페셜 저지 (0) | 2022.11.30 |
[C++] 백준 2670 - 연속부분최대곱(with setprecision) (0) | 2022.11.28 |
[C++] 백준 20291번 - 파일 정리 (0) | 2022.09.27 |
[C++] 백준 14938번 - 서강그라운드 (0) | 2022.09.24 |
Comments