A Game

时间限制:10000ms
单点时限:1000ms
内存限制:256MB

描述

Little Hi and Little Ho are playing a game. There is an integer array in front of them. They take turns (Little Ho goes first) to select a number from either the beginning or the end of the array. The number will be added to the selecter's score and then be removed from the array.

Given the array what is the maximum score Little Ho can get? Note that Little Hi is smart and he always uses the optimal strategy.

输入

The first line contains an integer N denoting the length of the array. (1 ≤ N ≤ 1000)

The second line contains N integers A1A2, ... AN, denoting the array. (-1000 ≤ Ai ≤ 1000)

输出

Output the maximum score Little Ho can get.

样例输入
4
-1 0 100 2
样例输出
99
分析:枚举区间长度和起点,动态规划
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <ext/rope>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define vi vector<int>
#define pii pair<int,int>
#define mod 1000000007
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
const int maxn=1e3+;
const int dis[][]={,,-,,,-,,};
using namespace std;
using namespace __gnu_cxx;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m,dp[maxn][maxn],a[maxn],sum[maxn];
int main()
{
int i,j,k,t;
scanf("%d",&n);
rep(i,,n)scanf("%d",&a[i]),dp[i][]=a[i],sum[i]=sum[i-]+a[i];
rep(i,,n)
{
for(j=;j+i-<=n;j++)
{
dp[j][i]=max(sum[j+i-]-sum[j-]-dp[j][i-],sum[j+i-]-sum[j-]-dp[j+][i-]);
}
}
printf("%d\n",dp[][n]);
//system("pause");
return ;
}
 

随机推荐

  1. Ubuntu cron定时执行任务

    1.添加自定义事件 crontab -e 2.选定编辑器 3.添加执行代码 * * * * /usr/bin/curl http://www.exmple.com/cron.php crontab 命 ...

  2. ZOJ 2158 POJ 1789 Truck History

    最小生成树,主要是题目比较难懂. #include <cstdio> #include <cstring> #include <cmath> #include &l ...

  3. iosNSMutableAttributedString 简单操作

    // 打印系统中所有字体的类型名字    NSArray *familyNames = [UIFont familyNames];    for(NSString *familyName in fam ...

  4. iOS打上线包或者测试包详细流程

    首先登陆苹果官方开发者账号:http://developer.apple.com 进入到如下界面 之后进入如下界面:点击第二项创建证书 整个流程如下图4步 然后按照如下图片进行配置即可 接下来去创建C ...

  5. 【2】docker 与UFW

    ufw是一个主机端的iptables类防火墙配置工具. 1.查看ufw的状态:ufw status 2.如果使用UFW,需要对其进行修改才能让DOCKER工作.docker使用一个网桥来管理容器中的网 ...

  6. Ajax应用-Ajax传输JSON数据实例

    ———————————————————— <script type="text/javascript">            var client;          ...

  7. Boxes in a Line(移动盒子)

      You have n boxes in a line on the table numbered 1 . . . n from left to right. Your task is to sim ...

  8. 不同版本的Api控件显示可能不同

    同样的一个布局, compileSdkVersion 24(android7.0)和 compileSdkVersion 18(android4.3)得到的结果可能不一样: <FrameLayo ...

  9. Qt学习

    博客 一去丶二三里的博客 http://blog.sina.com.cn/s/articlelist_2801495241_0_4.html

  10. mysql 连接两列

    以下划线符号,连接两列,作为查询结果: SELECT CONCAT(col_1,'_',col_2) FROM yourtable