-
Notifications
You must be signed in to change notification settings - Fork 3
/
lightoj 1031.cpp
66 lines (47 loc) · 943 Bytes
/
lightoj 1031.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
56
57
58
59
60
61
62
63
64
65
66
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define mx 105
int a[mx+10];
int dp[mx][mx];
int visit[mx][mx];
char ch[mx+10];
int n,ii;
int func(int i,int j)
{
if(i>j)return 0;
if(i==j)return a[i];
int &re=dp[i][j];
if(visit[i][j]==ii)return re;
visit[i][j]==ii;
re=INT_MIN;
int val=0;
for(int start=i;start<=j;start++)
{
val+=a[start];
re=max(re,val-func(start+1,j));
}
val=0;
for(int start=j;start>=i;start--)
{
val+=a[start];
re=max(re,val-func(i,start-1));
}
return re;
}
void solve(int l)
{
ii=l;
scanf("%d",&n);
for(int i=0;i<n;i++)scanf("%d",&a[i]);
printf("Case %d: %d\n",ii,func(0,n-1));
return;
}
int main()
{
int t=1;
scanf("%d",&t);
for(int i=1;i<=t;i++)solve(i);
return 0;
}