1. Problem
2. My Solution
import sys
n = int(sys.stdin.readline().rstrip())
seqeunce = list(map(int,sys.stdin.readline().rstrip().split()))
dp = [0] * n
dp[0] = seqeunce[0]
for i in range(1,n):
for j in range(i):
if seqeunce[i] > seqeunce[j]:
dp[i] = max(dp[i], dp[j]+seqeunce[i])
print(max(dp))
import sys
n = int(sys.stdin.readline().rstrip())
seqeunce = list(map(int,sys.stdin.readline().rstrip().split()))
dp = [0] * n
for i in range(n):
dp[i] = seqeunce[i]
for i in range(1,n):
for j in range(i):
if seqeunce[i] > seqeunce[j]:
dp[i] = max(dp[i], dp[j]+seqeunce[i])
print(max(dp))
3. Learned
1. Problem
2. My Solution
import sys
n = int(sys.stdin.readline().rstrip())
sequence = list(map(int,sys.stdin.readline().rstrip().split()))
dp = [[1,1] for _ in range(n)]
result = 0
for i in range(1,n):
for j in range(i):
if sequence[i] > sequence[j]:
dp[i][0] = max(dp[i][0], dp[j][0]+1)
elif sequence[i] < sequence[j]:
dp[i][1] = max(dp[i][1], dp[j][0]+1, dp[j][1]+1)
for i in range(n):
if result < max(dp[i]):
result = max(dp[i])
print(result)
3. Others' Solutions