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 | 31 |
Tags
- Operating System
- DP
- Computer science
- 컴공
- vector
- 알고리즘
- 컴공과
- 정석
- 오에스
- 백준
- cs
- bfs
- Stack
- 북리뷰
- 오퍼레이팅시스템
- 브루트포스
- c++
- 문제풀이
- 자료구조
- 코테
- 그래프
- 코딩
- 개발
- 너비우선탐색
- 구현
- 정석학술정보관
- 스택
- OS
- 컴퓨터공학과
- coding
Archives
- Today
- Total
Little Jay
[C++] 백준 1912번 - 연속합 본문
DP를 사용하는 문제
DP의 합과 입력받은 arr의 숫자를 잘 비교하면 되는 것 같다.
#include <iostream>
#include <vector>
using namespace std;
int arr[100001]{ 0, };
int dp[100001]{ 0, };
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
}
dp[1] = arr[1];
int result = dp[1];
for (int i = 2; i <= n; i++) {
dp[i] = max(dp[i - 1] + arr[i], arr[i]);
result = max(result, dp[i]);
}
cout << result << "\n";
return 0;
}'알고리즘 > BOJ' 카테고리의 다른 글
| [C++] 백준 11508번 - 2 + 1 세일 (0) | 2021.08.21 |
|---|---|
| [C++] 백준 2702번 - 초6 수학 (0) | 2021.08.21 |
| [C++] 백준 1850번 - 최대공약수 (0) | 2021.08.21 |
| [C++] 백준 5430번 틀 (0) | 2021.08.20 |
| [C++] 백준 9093번 - 단어 뒤집기 (0) | 2021.08.19 |
Comments