当前位置: 首页 > news >正文

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+10;
const int dis[][2]={0,1,-1,0,0,-1,1,0};
using namespace std;
using namespace __gnu_cxx;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
int n,m,dp[maxn][maxn],a[maxn],sum[maxn];
int main()
{
    int i,j,k,t;
    scanf("%d",&n);
    rep(i,1,n)scanf("%d",&a[i]),dp[i][1]=a[i],sum[i]=sum[i-1]+a[i];
    rep(i,2,n)
    {
        for(j=1;j+i-1<=n;j++)
        {
            dp[j][i]=max(sum[j+i-1]-sum[j-1]-dp[j][i-1],sum[j+i-1]-sum[j-1]-dp[j+1][i-1]);
        }
    }
    printf("%d\n",dp[1][n]);
    //system("pause");
    return 0;
}

 

 

转载于:https://www.cnblogs.com/dyzll/p/5666104.html

相关文章:

  • 选择最适合你的Linux学习方法
  • 什么是GPS的冷启动、温启动和热启动?
  • Clone
  • 正则表达式学习
  • 2205 Problem B
  • [React]全自动数据表格组件——BodeGrid
  • csv格式导出文件
  • ASP.NET MVC进阶之路:深入理解依赖注入(DI)和控制反转(IOC)
  • 关闭listener监听日志
  • 文成小盆友python-num11-(1) 线程 进程 协程
  • 基于复制的高可用
  • IDA Pro使用
  • C#程序员应该养成的程序性能优化写法
  • 在python 中is和= = 的区别
  • 用U盘安装Ubuntu系统
  • $translatePartialLoader加载失败及解决方式
  • .pyc 想到的一些问题
  • “Material Design”设计规范在 ComponentOne For WinForm 的全新尝试!
  • 【附node操作实例】redis简明入门系列—字符串类型
  • 【每日笔记】【Go学习笔记】2019-01-10 codis proxy处理流程
  • 10个最佳ES6特性 ES7与ES8的特性
  • Docker 1.12实践:Docker Service、Stack与分布式应用捆绑包
  • electron原来这么简单----打包你的react、VUE桌面应用程序
  • Java 网络编程(2):UDP 的使用
  • Python中eval与exec的使用及区别
  • session共享问题解决方案
  • Webpack4 学习笔记 - 01:webpack的安装和简单配置
  • 闭包,sync使用细节
  • 深入体验bash on windows,在windows上搭建原生的linux开发环境,酷!
  • 手写双向链表LinkedList的几个常用功能
  • 在Docker Swarm上部署Apache Storm:第1部分
  • 【运维趟坑回忆录 开篇】初入初创, 一脸懵
  • ​第20课 在Android Native开发中加入新的C++类
  • ![CDATA[ ]] 是什么东东
  • # 深度解析 Socket 与 WebSocket:原理、区别与应用
  • (1/2) 为了理解 UWP 的启动流程,我从零开始创建了一个 UWP 程序
  • (22)C#传智:复习,多态虚方法抽象类接口,静态类,String与StringBuilder,集合泛型List与Dictionary,文件类,结构与类的区别
  • (Note)C++中的继承方式
  • (附源码)springboot炼糖厂地磅全自动控制系统 毕业设计 341357
  • (附源码)ssm本科教学合格评估管理系统 毕业设计 180916
  • (附源码)计算机毕业设计SSM疫情居家隔离服务系统
  • (紀錄)[ASP.NET MVC][jQuery]-2 純手工打造屬於自己的 jQuery GridView (含完整程式碼下載)...
  • (算法)前K大的和
  • (学习日记)2024.01.09
  • (转)Unity3DUnity3D在android下调试
  • ***汇编语言 实验16 编写包含多个功能子程序的中断例程
  • .aanva
  • .Net 访问电子邮箱-LumiSoft.Net,好用
  • .NetCore Flurl.Http 升级到4.0后 https 无法建立SSL连接
  • @requestBody写与不写的情况
  • @RequestParam,@RequestBody和@PathVariable 区别
  • @SentinelResource详解
  • @synthesize和@dynamic分别有什么作用?
  • @Transaction注解失效的几种场景(附有示例代码)
  • [ vulhub漏洞复现篇 ] Django SQL注入漏洞复现 CVE-2021-35042