-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
## 백준 11055 | ||
https://www.acmicpc.net/problem/11055 | ||
|
||
> 수열 A가 주어졌을 때, 그 수열의 증가 부분 수열 중에서 합이 가장 큰 것을 구하는 프로그램을 작성하시오. | ||
### 소스코드 | ||
```py | ||
N = int(input()) | ||
|
||
A = input().split() | ||
A = map(int, A) | ||
A = list(A) | ||
|
||
length = A.copy() | ||
|
||
for i in range(len(A)): | ||
for j in range(i + 1): | ||
if A[j] < A[i]: | ||
length[i] = max(length[i], length[j] + A[i]) | ||
|
||
print(max(length)) | ||
|
||
``` | ||
|
||
### 해설 | ||
기본적인 LIS 문제에, 수열의 길이가 아닌 합을 요구하는 문제다. 때문에 +1 대신 원소를 더하고(`A[i]`), dp 배열에는 `A`를 기본값으로 넣어 최장 수열의 길이가 1인 경우부터 시작하도록 한다. |