-
Notifications
You must be signed in to change notification settings - Fork 2
/
l.cpp
55 lines (43 loc) · 982 Bytes
/
l.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 1e9 + 7;
ll int INF = 1e17;
ll int arr[3005];
ll int dp[3005][3005][2];
ll int kil(int l, int r, int player)
{
if(l == r)
{
if(player)
return arr[l];
return -arr[l];
}
if(dp[l][r][player] != -1)
return dp[l][r][player];
if(player)
{
dp[l][r][player] = -1e15;
dp[l][r][player] = max(dp[l][r][player], kil(l+1, r, 1-player) + arr[l]);
dp[l][r][player] = max(dp[l][r][player], kil(l, r-1, 1-player) + arr[r]);
}
else
{
dp[l][r][player] = 1e15;
dp[l][r][player] = min(dp[l][r][player], kil(l+1, r, 1-player) - arr[l]);
dp[l][r][player] = min(dp[l][r][player], kil(l, r-1, 1-player) - arr[r]);
}
return dp[l][r][player];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
memset(dp, -1, sizeof dp);
int n, k, res;
cin>>n;
for(int i=0;i<n;i++)
cin>>arr[i];
cout<<kil(0, n-1, 1)<<endl;
return 0;
}