[ BOJ / C++ ] 13398๋ฒ ์ฐ์ํฉ 2
ํ์ด์ฌ์ผ๋ก ํ์ด๋ดค๋ ์ฝ๋๋ฅผ C++๋ก ๋ค์ ํ๋ฒ ํ์ด๋ณด์๋ค. ํ์ด์ฌ ์ฝ๋์ ๊ฐ์ ๋ฐฉ์์ผ๋ก ํ์ดํ์๊ธฐ ๋๋ฌธ์ ์ค๋ช
์ ์๋ตํ๋ค.
[ BOJ / Python ] 13398๋ฒ ์ฐ์ํฉ 2
Code
#include <iostream>
#include <algorithm>
#define MAX 100001
using namespace std;
int n;
int arr[MAX];
int dp[MAX][2];
int answer=-999999999;
void Input(){
cin>>n;
for(int i=0; i<n; i++){
cin>>arr[i];
dp[i][0]=arr[i];
dp[i][1]=-999999999;
}
}
void Solution(){
for(int i=1; i<n; i++){
dp[i][0]=max(dp[i-1][0]+arr[i], arr[i]);
dp[i][1]=max(dp[i-1][0], dp[i-1][1]+arr[i]);
}
for(int i=0; i<n; i++){
answer=max(answer, max(dp[i][0], dp[i][1]));
}
cout<<answer<<endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
Input();
Solution();
return 0;
}
Author And Source
์ด ๋ฌธ์ ์ ๊ดํ์ฌ([ BOJ / C++ ] 13398๋ฒ ์ฐ์ํฉ 2), ์ฐ๋ฆฌ๋ ์ด๊ณณ์์ ๋ ๋ง์ ์๋ฃ๋ฅผ ๋ฐ๊ฒฌํ๊ณ ๋งํฌ๋ฅผ ํด๋ฆญํ์ฌ ๋ณด์๋ค https://velog.io/@xx0hn/BOJ-C-13398๋ฒ-์ฐ์ํฉ-2์ ์ ๊ท์: ์์์ ์ ๋ณด๊ฐ ์์์ URL์ ํฌํจ๋์ด ์์ผ๋ฉฐ ์ ์๊ถ์ ์์์ ์์ ์ ๋๋ค.
์ฐ์ํ ๊ฐ๋ฐ์ ์ฝํ
์ธ ๋ฐ๊ฒฌ์ ์ ๋
(Collection and Share based on the CC Protocol.)
์ข์ ์นํ์ด์ง ์ฆ๊ฒจ์ฐพ๊ธฐ
๊ฐ๋ฐ์ ์ฐ์ ์ฌ์ดํธ ์์ง
๊ฐ๋ฐ์๊ฐ ์์์ผ ํ ํ์ ์ฌ์ดํธ 100์ ์ถ์ฒ ์ฐ๋ฆฌ๋ ๋น์ ์ ์ํด 100๊ฐ์ ์์ฃผ ์ฌ์ฉํ๋ ๊ฐ๋ฐ์ ํ์ต ์ฌ์ดํธ๋ฅผ ์ ๋ฆฌํ์ต๋๋ค