From e288bf1c1e92dd16fcdca62218f7e2d24f064801 Mon Sep 17 00:00:00 2001 From: wnsmir <163817041+wnsmir@users.noreply.github.com> Date: Sun, 1 Dec 2024 01:57:00 +0900 Subject: [PATCH] 10-wnsmir --- ...2\260\234\353\257\270\354\240\204\354\202\254.py" | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 "wnsmir/DP/\352\260\234\353\257\270\354\240\204\354\202\254.py" diff --git "a/wnsmir/DP/\352\260\234\353\257\270\354\240\204\354\202\254.py" "b/wnsmir/DP/\352\260\234\353\257\270\354\240\204\354\202\254.py" new file mode 100644 index 0000000..dd82ef9 --- /dev/null +++ "b/wnsmir/DP/\352\260\234\353\257\270\354\240\204\354\202\254.py" @@ -0,0 +1,12 @@ +N = int(input()) + +Food = list(map(int, input().split())) + +dp = [0]*(N+1) +dp[1] = Food[0] +dp[2] = max(Food[0], Food[1]) + +for i in range(4, N+1): + dp[i] = max(dp[i-2]+Food[i-1], dp[i-1]) + +print(dp[N]) \ No newline at end of file