[BOJ] 11055번 : 가장 큰 증가하는 부분 수열
2024. 9. 2. 07:31ㆍAlgorithm
1. problem :
#include <bits/stdc++.h>
using namespace std;
int n;
int nums[1005];
int d[1005];
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> nums[i];
d[i] = nums[i];
}
for (int i = 2; i <= n; i++) {
for (int j = 1; j < i; j++) {
if (nums[i] > nums[j]) d[i] = max(d[i], d[j] + nums[i]);
}
}
cout << *max_element(d + 1, d + n + 1);
}
3. soluion 2:
// Authored by : Hot6Mania
// Co-authored by : -
// http://boj.kr/d478c2a6be29437f80e4e280de054d12
#include <bits/stdc++.h>
using namespace std;
int n;
int a[1010], d[1010];
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i];
d[i] = a[i];
}
for (int i = 0; i < n; ++i)
for (int j = 0; j < i; ++j)
if (a[j] < a[i]) d[i] = max(d[i], d[j] + a[i]);
cout << *max_element(d, d + n);
}
soure code 출처 : https://github.com/encrypted-def/basic-algo-lecture/blob/master/0x10/solutions/11055.cpp
basic-algo-lecture/0x10/solutions/11055.cpp at master · encrypted-def/basic-algo-lecture
바킹독의 실전 알고리즘 강의 자료. Contribute to encrypted-def/basic-algo-lecture development by creating an account on GitHub.
github.com
'Algorithm' 카테고리의 다른 글
[BOJ] 9461번 : 파도반 수열 (1) | 2024.09.02 |
---|---|
[BOJ] 11053번 : 가장 긴 증가하는 부분 수열 (1) | 2024.09.02 |
[BOJ] 1912번 : 연속합 (0) | 2024.09.01 |
[BOJ] 1654번 : 랜선 자르기 (0) | 2024.09.01 |
[BOJ] 2193번 : 이친수 (0) | 2024.09.01 |