题目1 : 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

AC代码:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int a[], dp[][], s[];
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
int n;
scanf("%d", &n);
for (int i = ; i <= n; i++) {
scanf("%d", &a[i]);
}
memset(dp, , sizeof(dp));
s[] = ;
s[] = a[];
for (int i = ; i <= n; i++) {
s[i] = s[i - ] + a[i];
}
for (int i = ; i <= n; i++) {
dp[i][i] = a[i];
dp[i][i + ] = a[i] > a[i + ] ? a[i] : a[i + ];
}
for (int i = n; i >= ; i--) {
for (int j = i + ; j <= n; j++) {
dp[i][j] = dp[i + ][j] > dp[i][j - ] ? s[j] - s[i - ] - dp[i][j - ] : s[j] - s[i - ] - dp[i + ][j];
}
}
printf("%d\n", dp[][n]);
return ;
}

WA代码:

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int a[], dp[][], s[];
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
int n;
scanf("%d", &n);
for (int i = ; i <= n; i++) {
scanf("%d", &a[i]);
}
memset(dp, , sizeof(dp));
s[] = ;
s[] = a[];
for (int i = ; i <= n; i++) {
s[i] = s[i - ] + a[i];
}
for (int i = ; i <= n; i++) {
dp[i][i] = a[i];
dp[i][i + ] = a[i] > a[i + ] ? a[i] : a[i + ];
}
for (int i = ; i <= n; i++) {
for (int j = ; j + i - <= n; j++) {
int tmp = -;
//j+1->j+i-1
if (a[j] + (s[j + i - ] - s[j]) - dp[j + ][j + i - ] > tmp) {
tmp = a[j] + (s[j + i - ] - s[j]) - dp[j + ][j + i - ];
}
//j->j+i-2
if (a[j + i - ] + (s[j + i - ] - s[j - ]) - dp[j][j + i - ] > tmp) {
tmp = a[j + i - ] + (s[j + i - ] - s[j - ]) - dp[j][j + i - ];
}
dp[j][j + i - ] = tmp;
}
}
printf("%d\n", dp[][n]);
return ;
}

思路一样,就是不知道为什么不对。

几个小时之后,两种都不对了。那你特么倒是解释解释这是怎么回事啊?

真操蛋,这种问题遇到无数次了。

OK了,辣鸡OJ评测机有问题。

hiho一下 第173周的更多相关文章

  1. 圆内,求离圆心最远的整数点 hiho一下第111周 Farthest Point

    // 圆内,求离圆心最远的整数点 hiho一下第111周 Farthest Point // 思路:直接暴力绝对T // 先确定x范围,每个x范围内,离圆心最远的点一定是y轴两端的点.枚举x的范围,再 ...

  2. hiho一下 第115周:网络流一•Ford-Fulkerson算法 (Edmond-Karp,Dinic,SAP)

    来看一道最大流模板水题,借这道题来学习一下最大流的几个算法. 分别用Edmond-Karp,Dinic ,SAP来实现最大流算法. 从运行结过来看明显SAP+当前弧优化+gap优化速度最快.   hi ...

  3. 【hiho一下第77周】递归-减而治之 (MS面试题:Koch Snowflake)

    本题是一道微软面试题,看起来复杂,解出来会发现其实是一个很简单的递归问题,但是这道题的递归思路是很值得我们反复推敲的. 原题为hihocoder第77周的题目. 描述 Koch Snowflake i ...

  4. hiho一下 第207周

    题目1 : The Lastest Time 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 What is latest time you can make with ...

  5. hiho一下第128周 后缀自动机二·重复旋律5

    #1445 : 后缀自动机二·重复旋律5 时间限制:10000ms 单点时限:2000ms 内存限制:512MB 描述 小Hi平时的一大兴趣爱好就是演奏钢琴.我们知道一个音乐旋律被表示为一段数构成的数 ...

  6. 【hiho一下】第一周 最长回文子串

    题目1:最长回文子串 题目原文:http://hihocoder.com/contest/hiho1/problem/1 [题目解读] 题目与 POJ 3974 palindrome 基本同样.求解最 ...

  7. Solution: 最近公共祖先·一 [hiho一下 第十三周]

    题目1 : 最近公共祖先·一 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Ho最近发现了一个神奇的网站!虽然还不够像58同城那样神奇,但这个网站仍然让小Ho乐在其中 ...

  8. hiho一下十六周 RMQ-ST算法

    RMQ-ST算法 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho在美国旅行了相当长的一段时间之后,终于准备要回国啦!而在回国之前,他们准备去超市采购一些当 ...

  9. hiho一下 第九十七周 数论六·模线性方程组

    题目1 : 数论六·模线性方程组 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Ho:今天我听到一个挺有意思的故事! 小Hi:什么故事啊? 小Ho:说秦末,刘邦的将军 ...

随机推荐

  1. Java 各级注解及@Autowired注入为null解决办法

    1.@controller 控制器 用于标注控制层,相当于struts中的action层. 2.@service 服务层 用于标注服务层,主要用来进行业务的逻辑处理. 3.@repository DA ...

  2. vue中用v-for循环出出来的div下面的span不给宽度也能相对于div居中

    效果图 1.html <div> <div v-on:mousemove="dataDetails($event, item)" v-on:mouseleave= ...

  3. JDBC对MySQL数据库存储过程的调用

    一.MySQL数据库存储过程: 1.什么是存储过程 存储过程(英文:Stored Procedure)是在大型数据库系统中,为了完成特定功能而编写的一组的SQL语句集.存储过程经编译存储在数据库中,用 ...

  4. SSO 单点登录解决方案

    转自:http://www.blogjava.net/Jack2007/archive/2014/03/11/191795.html 1 什么是单点登陆      单点登录(Single Sign O ...

  5. 实验吧writeup

    后台登录 1.看源码有这样一段php代码<!-- $password=$_POST['password']; $sql = "SELECT * FROM admin WHERE use ...

  6. Linux思维导图之查找命令

    常用查找命令的区别:

  7. Automatic Tuning of Memory Management

    4.2.2 Automatic Tuning of Memory Management Two memory management initialization parameters, MEMORY_ ...

  8. HDU4565 So Easy!

    /* HDU4565 So Easy! http://acm.hdu.edu.cn/showproblem.php?pid=4565 数论 快速幂 矩阵快速幂 题意:求[(a+sqrt(b))^n ] ...

  9. poj 3469 最小割模板sap+gap+弧优化

    /*以核心1为源点,以核心2为汇点建图,跑一遍最大流*/ #include<stdio.h> #include<string.h> #include<queue> ...

  10. hdu 4009 最小树形图模板题朱刘算法

    #include<stdio.h> /*思路:显然对于每个地方, 只有一种供水方式就足够了,这样也能保证花费最小, 而每个地方都可以自己挖井,所以是不可能出现无解的情况的, 为了方便思考, ...