zoukankan      html  css  js  c++  java
  • HihoCoder1338 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<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<iostream>
    using namespace std;
    int a[1010],dp[1010][1010];
    int getdp(int L,int R)
    {
        if(dp[L][R]) return dp[L][R];
        if(L == R) return a[L];
        if(L==R-1) dp[L][R]=max(a[L],a[R]);
        else dp[L][R]=max(a[L]+min(getdp(L+2,R),getdp(L+1,R-1)),a[R]+min(getdp(L,R-2),getdp(L+1,R-1)));
        return dp[L][R];
    }
    int main()
    {
        int n,i;
        scanf("%d",&n);
        for(i = 1;i <= n;i ++)  scanf("%d",&a[i]);
        printf("%d
    ",getdp(1,n));
        return 0;
    }
  • 相关阅读:
    dubbo
    常见线程池
    面试之葵花宝典
    Java线程池
    DB2分页
    平凡
    自由职业一时爽,一直自由一直爽
    弱水三千,只取一瓢。
    没病到一定程度,你千万别去。
    一个转身一个轮回
  • 原文地址:https://www.cnblogs.com/hua-dong/p/7955603.html
Copyright © 2011-2022 走看看