Bzoj 2101: [Usaco2010 dec]treasure Chest Treasure Chest (DP)

Source: Internet
Author: User

DP (l, r) = SUM (l, R)-Min (DP (l + 1, R), DP (L, R-1))

Be card space .... We can see that L > R is meaningless, so we can save half of the space.

--------------------------------------------------------------------------------

#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>#define REP (i, n) for (int i = 0; i < n; ++i)#define CLR (x, C) memset (x, C, sizeof (x))#define REP (i, n) for (int i = 1; I <= n; ++i)using namespace std;const INT MAXN = + +;int d[MAXN * MAXN >> 1];int sum[MAXN];int n; #define F (L, R) (R + (((n << 1)-L + 2) * (L-1) >> 1))int dp (int l, int r) {int &ans = d[F (l, R)];if (ans! =-1) return ans;return ans = sum[R]-sum[l-1]-min (DP (l + 1, R), DP (L, R-1));} int main () {freopen ("test.in", "R", stdin);cin >> N;sum[0] = 0;CLR (d,-1);Rep (i, n) {int v;scanf ("%d", &v);d[F (i, i)] = V;sum[i] = sum[i-1] + V;}cout << dp (1, N) << "\ n";return 0;}

--------------------------------------------------------------------------------

2101: [Usaco2010 dec]treasure Chest Treasure Box Time limit: ten Sec Memory Limit: MB
Submit: 374 Solved: 174
[Submit] [Status] [Discuss] Description

Bessie and Bonnie has 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 having some fun with the coin S. The n (1 <= n <= 5,000) coins, each with some value c_i (1 <= c_i <= 5,000) is 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 is no coins left. Bessie and Bonnie is 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 is lined up with these values:30 ten consider this game Sequence:bessie Bonnie New Coin Player Side coinvalue Total, line Bessie right, 0 Bonnie left, Bessie left 25 6 0 Bonnie Right Ten--the best game BessIE can play.

Bessie and Bonnie found a treasure chest with gold coins in it! But as two cows, they can't go to the storecoins for delicious food, so they can only use these gold coins to play the game. Treasure Chest A total of n gold coins, the value of the first coin is CI. Bessie and Bonnie lined up the coins in a straight line, and sheWe take turns to collect coins to see who gets the most money. Bessie takes only one gold coin at a time, and only chooses to take a straight linegold coins at both ends cannot be taken away from the middle. When all the coins are finished, the game is over. both Bessie and Bonnie are very smart, and they will use the best way to get the most out of their coins. Please help the PayPalWest Calculate how much she can get? Input

* Line 1: A single integer:n * Lines 2..n+1:line i+1 contains A single integer:c_i

First line: A single integer N, indicating the number of coins, 1<=n≤5000Line two to n+1: line I+l has an integer Ci representing the value of block I coins, 1≤ci≤5000Output

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

First line: A single integer that indicates the maximum value that the initiator can get if both parties play the game according to the optimal strategySample Input4
30
25
10
35

Sample Output60

HINT

( the best way to do this is to take it first , then Bonnie will take it, and Bessie takes it, andBonnie finally takes Ten)

Source

Silver

Bzoj 2101: [Usaco2010 dec]treasure Chest Treasure Chest (DP)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.