프로그래밍/HackerRank
[HackerRank][Python3] Max Array Sum
snoopybox
2018. 7. 18. 15:43
Problem :
https://www.hackerrank.com/challenges/max-array-sum/problem
My Solution :
#!/usr/bin/env python3 def maxSubsetSum(arr): if len(arr) == 1: return arr[0] dp = [arr[0], max(arr[:2])] + [0]*(len(arr)-2) for i in range(2, len(arr)): dp[i] = max(arr[i], dp[i-1], dp[i-2]+arr[i]) return dp[-1] n = int(input()) arr = list(map(int, input().rstrip().split())) res = maxSubsetSum(arr) print(res)