A Game

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. 【Win 10 应用开发】通过数据绑定更新进度条

    实现 INotifyPropertyChanged 接口可以在属性更改后通知数据的使用者,这个相信大伙儿都知道.于是,有朋友会问:对于要实时显示进度的情况,比如更新进度条,能用这个实现吗? 当然是可以 ...

  2. HTML中使图片居中显示

    注:imageId为图片id<style type="text/css"> #imageId{ display:block; position:relative; ma ...

  3. Git学习(一)——Git介绍与安装

    一.Git诞生 Linus在1991年创建了Linux,从此,Linux系统不断发展,成为最大的服务器系统软件. 2005年,Linus用C编写了一个分布式版本控制工具--Git. 二.集中式vs分布 ...

  4. caffe简易上手指南(二)—— 训练我们自己的数据

    训练我们自己的数据 本篇继续之前的教程,下面我们尝试使用别人定义好的网络,来训练我们自己的网络. 1.准备数据 首先很重要的一点,我们需要准备若干种不同类型的图片进行分类.这里我选择从ImageNet ...

  5. Java的数组,集合,数据结构,算法(一)

    本人的愚见,博客是自己积累对外的输出,在学习初期或自己没有多少底料的情况下,与其总结写博客不如默默去搞自己的代码,但是学到集合这一块时,数组,集合,数据结构,算法这个概念搞的我比较混淆,所以不得已写这 ...

  6. RNN入门(一)识别MNIST数据集

    RNN介绍   在读本文之前,读者应该对全连接神经网络(Fully Connected Neural Network, FCNN)和卷积神经网络( Convolutional Neural Netwo ...

  7. j假设程序需要要一个int烈血的刀变量来保存1英里所包含的步数(5280)为该变量编写一条声明语句。

    j假设程序需要要一个int烈血的刀变量来保存1英里所包含的步数(5280)为该变量编写一条声明语句. final intFT_PER_MILE =5280

  8. 洛谷P2572 &lbrack;SCOI2010&rsqb;序列操作&lpar;ODT&rpar;

    题解 题意 题目链接 Sol ODT板子题..... // luogu-judger-enable-o2 #include<bits/stdc++.h> #define LL long l ...

  9. java中使用jxl读取excel中的数据

    package bboss; import java.io.File; import java.io.FileInputStream; import java.io.IOException; impo ...

  10. 20155323刘威良《网络对抗》Exp6 信息搜集与漏洞扫描

    20155323刘威良<网络对抗>Exp6 信息搜集与漏洞扫描 实践目标 掌握信息搜集的最基础技能与常用工具的使用方法. 实践内容 (1)各种搜索技巧的应用 (2)DNS IP注册信息的查 ...

上一篇:利用Maven管理工程项目本地启动报错及解决方案


下一篇:【WP 8.1开发】解决调用真实摄像头会死机的问题