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. Redis简介二

    一.直接安装     1.Windows版本的Redis下载地址:https://github.com/dmajkic/redis/downloads  ,选择一个你想要下载的版本下载即可~     ...

  2. 使用非 GUI 模式运行 JMeter 压力测试

    使用非 GUI 模式,即命令行模式运行 JMeter 测试脚本能够大大缩减所需要的系统资源.使用命令jmeter -n -t <testplan filename> -l <list ...

  3. Chapter 2 Open Book——8

    But as far as I could tell, life worked that way most of the time. 但是即使我这么说,生活大多数时间还是这样的. 但就我所能告诉你的, ...

  4. scala与java的==的比较

    如果你想比较一下看看两个对象是否相等,可以使用或者==,或它的反义 !=.(对所有对象都适用,而不仅仅是基本数据类型) ? 1 2 3 4 scala> 1 ==  2 res24: Boole ...

  5. nefu 1029 字符串

    Description 给定一个字符串,现在要你从这个字符串中找到第一个只出现一次的字符 ,很简单吧! 快敲代码,动作! Input 多组输入,每行一个字符串(小写字母a~z)字符串长度不超过50 O ...

  6. 【Machine Learning in Action --1】机器学习入门指南

    摘自:http://www.jianshu.com/p/c3634a7f2320 机器学习算法 Coursera 上面 Stanford 的 机器学习 课程是优质的算法相关入门课程.Andrew Ng ...

  7. repeat a string in java

    if I want to repeat "hello" four times as a new string-> "hellohellohellohello&quo ...

  8. flash cs6 更新到Flash player15.0 及Air 更新方法

    1.自行下载Air 15.0 sdk (Flash player 包含在内) 2.  到15.0Air 包 里找player :AIR15.0\frameworks\libs\player 里面有pl ...

  9. oc汉子转拼音

    oc中可以不使用第三方库直接吧数组转成拼音: 代码如下: NSString *str = @"中国abc人民共和国"; CFStringRef aCFString=(__bridg ...

  10. CAFFE中训练与使用阶段网络设计的不同

    神经网络中,我们通过最小化神经网络来训练网络,所以在训练时最后一层是损失函数层(LOSS), 在测试时我们通过准确率来评价该网络的优劣,因此最后一层是准确率层(ACCURACY). 但是当我们真正要使 ...