题目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. <meta http-equiv="refresh" content="3"> 什么意思?

    <meta http-equiv="refresh" content="3"> 什么意思?平常都是<meta http-equiv=" ...

  2. day35-2 类的三大特性---多态,以及菱形继承问题

    目录 菱形继承问题 经典类 新式类 菱形继承 大招 多态与多态性 多态 多态性 多态在Python中的体现 鸭子类型(重要) 结论 菱形继承问题 经典类 没有继承object类的就是经典类,只有Pyt ...

  3. 实验吧writeup

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

  4. C++ 对象创建的问题

    一.C++对象的创建: 对象创建的注意事项: 1.对象数组里的个数,就是创建对象的个数,普通数组一样:下标从0 到数组里数字 -1: 2.类名*  对象指针   <-->  这里只是一个指 ...

  5. 32.es读请示内部分发原理

    当客户端发送一次读请求时,大致会经过以下几个步骤 1.客户端发送一个请求过去,es的一个node接收到这个请求(随机的node),这个node就被es内部分配成coordinating node(协调 ...

  6. SQLServer · BUG分析 · Agent 链接泄露分析(转载)

    背景 SQLServer Agent作为Windows服务提供给用户定期执行管理任务,这些任务被称为Job:考虑应用镜像的场景如何解决Job同步问题,AWS RDS的做法是不予理会,由用户维护Job, ...

  7. Java设计模式之 — 单例(Singleton)

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/8860649 写软件的时候经常需要用到打印日志功能,可以帮助你调试和定位问题,项目上 ...

  8. Bootstrap内联表单

    有时候我们需要将表单的控件都在一行内显示,就需要将表单控件设置成内联块元素(display:inline-block). 在Bootstrap框架中实现这样的表单效果是轻而易举的,你只需要在<f ...

  9. 【Codeforces 342A】Xenia and Divisors

    [链接] 我是链接,点我呀:) [题意] [题解] 最后a,b,c只有以下3种情况 1,2,4 1,2,6 1,3,6 那么用cnt[8]统计每个数字出现的次数. 输出cnt[4]次1,2,4 (如果 ...

  10. 【ACM】poj_3981_字符串替换_201307271019

    字符串替换Time Limit: 1000MS  Memory Limit: 65536K Total Submissions: 8447  Accepted: 3988 Description 编写 ...