zoukankan      html  css  js  c++  java
  • 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
    ",dp[1][n]);
        //system("pause");
        return 0;
    }
     
  • 相关阅读:
    C语言学习之我见-strcpy()字符串复制函数
    豆邮windows客户端(第三方)开发详解
    项目管理的主要控制因素(转)
    daterangepicker -- bootstrap日期时间范围插件使用分享
    Jacob
    Selenium
    基本套接字总结(@function)
    Python字符串处理NoneType的处理
    机器学习相关会议(转载)
    jboss-AS目录结构了解(资料摘取)
  • 原文地址:https://www.cnblogs.com/dyzll/p/5666104.html
Copyright © 2011-2022 走看看