PS/백준

[BOJ] 백준 5945번 : Treasure Chest (JAVA)

제이온 (Jayon) 2020. 10. 6.

문제

Bessie and Bonnie have found a treasure chest full of marvelous gold coins! Being cows, though, they can't just walk into a store and buy stuff, so instead they decide to have some fun with the coins.

 

The N (1 <= N <= 5,000) coins, each with some value C_i (1 <= C_i <= 5,000) are placed in a straight line. Bessie and Bonnie take turns, and for each cow's turn, she takes exactly one coin off of either the left end or the right end of the line. The game ends when there are no coins left.

 

Bessie and Bonnie are each trying to get as much wealth as possible for themselves. Bessie goes first. Help her figure out the maximum value she can win, assuming that both cows play optimally.

 

Consider a game in which four coins are lined up with these values:

 

 

 

 

Consider this game sequence:

 

 

 

 

This is the best game Bessie can play.

 

 

입력

- Line 1: A single integer: N

- Lines 2..N+1: Line i+1 contains a single integer: C_i

 

 

출력

- Line 1: A single integer, which is the greatest total value Bessie can win if both cows play optimally.

 

 

풀이

"11062번 카드 게임"과 상당히 유사한 문제였습니다.

 

 

 

[BOJ] 백준 11062번 : 카드 게임 (JAVA)

문제 근우와 명우는 재미있는 카드 게임을 하고 있다. N개의 카드가 일렬로 놓여 있다. 각 카드에는 점수가 적혀있다. 근우부터 시작하여 번갈아가면서 턴이 진행되는데 한 턴에는 가장 왼쪽에 �

steady-coding.tistory.com

 

 

문제가 영어로 달라지고, 여러 케이스가 아닌 하나의 케이스에 대해서만 점수를 파악한다는 점에서 오히려 "11062번 카드 게임"보다 더 쉬운 문제였습니다.

 

 

문제가 겹치는 관계로 풀이는 위 포스팅을 읽어 보시고, 아래 소스코드를 참고하시면 되겠습니다.

 

 

소스코드

 

지적 혹은 조언 환영합니다! 언제든지 댓글로 남겨주세요.

댓글

추천 글