Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solved 포도주시식 - 124ms 14852KB #199

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Baekjoon/포도주시식/포도주시식_안창호.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import java.io.*;
import java.util.*;

class 포도주시식_안창호 {
static int n;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
n = Integer.parseInt(br.readLine());

int[] arr = new int[n + 1];
int[] dp = new int[n + 1];

for (int i = 1; i <= n; i++) {
arr[i] = Integer.parseInt(br.readLine());
}

dp[1] = arr[1];
if (n > 1) {
dp[2] = arr[1] + arr[2];
}

for (int i = 3; i <= n; i++) {
dp[i] = Math.max(dp[i - 1], Math.max(dp[i - 2] + arr[i], dp[i - 3] + arr[i - 1] + arr[i]));
}

System.out.println(dp[n]);
}
}
Loading