hiho一下 第173周
题目1 : A Game
描述
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 A1, A2, ... 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周的更多相关文章
- 圆内,求离圆心最远的整数点 hiho一下第111周 Farthest Point
// 圆内,求离圆心最远的整数点 hiho一下第111周 Farthest Point // 思路:直接暴力绝对T // 先确定x范围,每个x范围内,离圆心最远的点一定是y轴两端的点.枚举x的范围,再 ...
- hiho一下 第115周:网络流一•Ford-Fulkerson算法 (Edmond-Karp,Dinic,SAP)
来看一道最大流模板水题,借这道题来学习一下最大流的几个算法. 分别用Edmond-Karp,Dinic ,SAP来实现最大流算法. 从运行结过来看明显SAP+当前弧优化+gap优化速度最快. hi ...
- 【hiho一下第77周】递归-减而治之 (MS面试题:Koch Snowflake)
本题是一道微软面试题,看起来复杂,解出来会发现其实是一个很简单的递归问题,但是这道题的递归思路是很值得我们反复推敲的. 原题为hihocoder第77周的题目. 描述 Koch Snowflake i ...
- hiho一下 第207周
题目1 : The Lastest Time 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 What is latest time you can make with ...
- hiho一下第128周 后缀自动机二·重复旋律5
#1445 : 后缀自动机二·重复旋律5 时间限制:10000ms 单点时限:2000ms 内存限制:512MB 描述 小Hi平时的一大兴趣爱好就是演奏钢琴.我们知道一个音乐旋律被表示为一段数构成的数 ...
- 【hiho一下】第一周 最长回文子串
题目1:最长回文子串 题目原文:http://hihocoder.com/contest/hiho1/problem/1 [题目解读] 题目与 POJ 3974 palindrome 基本同样.求解最 ...
- Solution: 最近公共祖先·一 [hiho一下 第十三周]
题目1 : 最近公共祖先·一 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Ho最近发现了一个神奇的网站!虽然还不够像58同城那样神奇,但这个网站仍然让小Ho乐在其中 ...
- hiho一下十六周 RMQ-ST算法
RMQ-ST算法 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho在美国旅行了相当长的一段时间之后,终于准备要回国啦!而在回国之前,他们准备去超市采购一些当 ...
- hiho一下 第九十七周 数论六·模线性方程组
题目1 : 数论六·模线性方程组 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Ho:今天我听到一个挺有意思的故事! 小Hi:什么故事啊? 小Ho:说秦末,刘邦的将军 ...
随机推荐
- BZOJ 3036: 绿豆蛙的归宿 期望 + 拓扑排序
随着新版百度空间的下线,Blog宠物绿豆蛙完成了它的使命,去寻找它新的归宿.给出一个有向无环的连通图,起点为1终点为N,每条边都有一个长度.绿豆蛙从起点出发,走向终点. 到达每一个顶点时,如果有K条离 ...
- 物理cpu与逻辑cpu概述
物理cpu与逻辑cpu概述(本博客属于转载部分内容:主要学习目的用于大数据平台Hadoop之yarn资源调度的配置) 一.yarn资源调度器中主要的资源分类 1.memory(内存) 2. ...
- jmeter的性能监控框架搭建记录(Influxdb+Grafana+Jmeter)
查看笔记 http://note.youdao.com/noteshare?id=c700365713abb98bd3d10e6f45393af9&sub=6F4E14FF3F9D4167AE ...
- Tost元素识别
在日常使用App过程中,经常会看到App界面有一些弹窗提示(如下图所示)这些提示元素出现后等待3秒左右就会自动消失,那么我们该如何获取这些元素文字内容呢? Toast简介 Android中的Toast ...
- Lua操作系统库、流、文件库
Lua操作系统库.流.文件库 1.Lua中所有的操作系统库函数 (1)os.clock() --功能:返回执行该程序cpu花费的时钟秒数 (2)os.time(...) --按参数的内容返回一个时间值 ...
- 使用Arcgis进行画面(线)并计算大小(长度)。
在使用Arcgis API for JavaScript进行做地图开发的过程中,在地图进行画线.画面是经常使用的功能.本文主要介绍这一功能. 本文适用Arcgis API版本:Arcgis API f ...
- 51nod1185 威佐夫游戏 V2【博弈论】
有2堆石子.A B两个人轮流拿,A先拿.每次可以从一堆中取任意个或从2堆中取相同数量的石子,但不可不取.拿到最后1颗石子的人获胜.假设A B都非常聪明,拿石子的过程中不会出现失误.给出2堆石子的数量, ...
- Ajax传递的参数如何在浏览器中查看
如图当需要在浏览器中知道Ajax传递的参数可以,点击浏览器的右键检查,点击XHR,此时要记得提交带有参数的Ajax页面, 这样才可以显示出来传递的参数
- C#学习笔记_02_数据类型
02_数据类型 基本数据类型 整型 有符号整型:最高位是正负号 字节型:sbyte 1byte:[-128,127] 短整型:short: 2byte:[-2^(位数-1),2^(位数-1)-1] 整 ...
- CodeForces 396C On Changing Tree
On Changing Tree Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces ...