feat: added alternative python solutions.
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -43,7 +43,7 @@
|
||||
},
|
||||
"solutions": {
|
||||
"main-ac": "ac.cpp",
|
||||
"alternative-ac": [],
|
||||
"alternative-ac": ["alternative-ac.py"],
|
||||
"wrong-answer": [],
|
||||
"time-limit": [],
|
||||
"time-limit-or-ac": [],
|
||||
|
||||
25
longest-increasing-subsequence/src/alternative-ac.py
Normal file
25
longest-increasing-subsequence/src/alternative-ac.py
Normal file
@@ -0,0 +1,25 @@
|
||||
n = int(input())
|
||||
a = list(map(int, input().split()))
|
||||
|
||||
dp = [1] * n
|
||||
parent = [-1] * n
|
||||
|
||||
for i in range(n):
|
||||
for j in range(i):
|
||||
if a[j] < a[i] and dp[j] + 1 > dp[i]:
|
||||
dp[i] = dp[j] + 1
|
||||
parent[i] = j
|
||||
|
||||
max_length = max(dp)
|
||||
max_index = dp.index(max_length)
|
||||
|
||||
lis = []
|
||||
idx = max_index
|
||||
while idx != -1:
|
||||
lis.append(a[idx])
|
||||
idx = parent[idx]
|
||||
|
||||
lis.reverse()
|
||||
|
||||
print(max_length)
|
||||
print(' '.join(map(str, lis)))
|
||||
Reference in New Issue
Block a user