Problem D. What a Beautiful Lake

Description

Weiming Lake, also named "Un-named Lake", is the most famous scenic spot in Peking University. It is located in the north of the campus and is surrounded by walking paths, small gardens, and old red buildings with typical Chinese curly roofs. The lake was once the royal garden in Qing Dynasty. Boya tower stands on a little hill beside the lake. The lake and the tower form a distinctive landscape and a symbol of Peking University.

Weiming Lake is a very good place for studying, reading, skating in the winter, and of course, jogging. More and more students and teachers run or walk around Weiming Lake every day and show how many paces they have covered in the mobile app WeChat Sports to get "Zans" (applauses).

ACMer X also enjoys jogging around Weiming Lake. His watch can measure and record an altitude value every meter. After a round of running, X collected the altitude data around the lake. Now he wants to find out the longest slope around the lake.

Input

There are no more than 20 test cases.

Each case has two lines.

The first line is an integer N (2 <= N <= 100) meaning that the length of the road around the lake is N meters.

The second line contains N integers a1,a2...aN, (0<= a1,a2...aN <= 100) indicating N altitude sample values around the lake. The samples are given in clockwise order, and the distance between two adjacent samples is one meter. Of course the distance between a1 and aN is also one meter.

The input ends by a line of 0.

Output

For each test case, print the length of the longest slope in meters. A slope is a part of the road around the lake, and it must keep going up or going down. If there are no slope, print 0.

Sample Input

4

1 1 1 1

8

5 1 2 3 4 5 6 2

6

5 4 3 2 1 2

10

1 0 2 3 2 2 3 4 3 2

0

Sample Output

0

5

4

4

用dp[i][0   or  1]表示是否比上一个小,或者大的时候,以a[i]为结尾的最大长度。

因为可以循环,所以就直接把数组复制一次在后面,形成2 * n的数组

如果相等就直接跳过好了。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string> int n;
const int maxn = 1e3 + ;
int dp[maxn][];
int a[maxn];
void work() {
for (int i = ; i <= n; ++i) {
cin >> a[i];
}
int t = n;
for (int i = ; i <= n; ++i) {
a[++t] = a[i];
}
memset(dp, , sizeof dp);
for (int i = ; i <= t; ++i) {
if (a[i] == a[i - ]) continue;
if (a[i] > a[i - ]) {
dp[i][] = dp[i - ][] + ;
} else dp[i][] = dp[i - ][] + ;
}
int ans = ;
for (int i = ; i <= t; ++i) {
ans = max(ans, dp[i][]);
ans = max(ans, dp[i][]);
}
cout << ans << endl;
} int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
IOS;
while (cin >> n && n) work();
return ;
}

Problem D. What a Beautiful Lake dp的更多相关文章

  1. hihocoder 1425What a Beautiful Lake(实验专用)

    Problem D. What a Beautiful Lake Description Weiming Lake, also named "Un-named Lake", is ...

  2. hihoCoder 1425 : What a Beautiful Lake(美丽滴湖)

    hihoCoder #1425 : What a Beautiful Lake(美丽滴湖) 时间限制:1000ms 单点时限:1000ms 内存限制:256MB Description - 题目描述 ...

  3. Problem D: 勤奋的涟漪2 dp + 求导

    http://www.gdutcode.sinaapp.com/problem.php?cid=1049&pid=3 dp[i][state]表示处理了前i个,然后当前状态是state的时候的 ...

  4. Aizu 2305 Beautiful Currency DP

    Beautiful Currency Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest ...

  5. Codeforces Gym 100610 Problem K. Kitchen Robot 状压DP

    Problem K. Kitchen Robot Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10061 ...

  6. Codeforces 713C Sonya and Problem Wihtout a Legend(单调DP)

    [题目链接] http://codeforces.com/problemset/problem/713/C [题目大意] 给出一个数列,请你经过调整使得其成为严格单调递增的数列,调整就是给某些位置加上 ...

  7. (中等) HDU 5293 Tree chain problem,树链剖分+树形DP。

    Problem Description   Coco has a tree, whose vertices are conveniently labeled by 1,2,…,n.There are ...

  8. Codeforces 1085G(1086E) Beautiful Matrix $dp$+树状数组

    题意 定义一个\(n*n\)的矩阵是\(beautiful\)的,需要满足以下三个条件: 1.每一行是一个排列. 2.上下相邻的两个元素的值不同. 再定义两个矩阵的字典序大的矩阵大(从左往右从上到下一 ...

  9. Problem D: 乌龟棋【四维dp】

    Problem D: 乌龟棋 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 24  Solved: 15[Submit][Status][Web Boa ...

随机推荐

  1. tomcat正常启动,但是java项目没有启动原因

    右键项目,选择properties,查看该属性配置的是否正确

  2. 使用jQuery集成Google翻译

    利用jQuery,轻松将google翻译集成到你的web应用中. 1. [代码][JavaScript]代码     ​1<script src="Scripts/Translator ...

  3. C++软件工程师,你该会什么?

    请尊重原创: 转载注明来源   原创在这里哦 C语言广泛用于基础软件.桌面系统.网络通信.音频视频.游戏娱乐等诸多领域.是世界上使用最广泛的编程语言之一.随着物联网技术的发展,C/C++技术在3G网络 ...

  4. yolo-开源数据集coco kitti voc

    1.kitti数据集(参考博客:https://blog.csdn.net/jesse_mx/article/details/65634482  https://blog.csdn.net/baoli ...

  5. APIO2015巴厘岛的雕塑——数位DP

    题目:https://www.luogu.org/problemnew/show/P3646 对于A>1,将答案各位全置1,然后从高位到低位改成0判断是否可行: 用f[i][j]数组代表前i个数 ...

  6. rsync(四)技术报告

    1.1 摘要 本报告介绍了一种将一台机器上的文件更新到和另一台机器上的文件保持一致的算法.我们假定两台机器之间通过低带宽.高延迟的双向链路进行通信.该算法计算出源文件中和目标文件中一致的部分(译者注: ...

  7. 转:CURL库在程序中的运用浅析

    CURL库在程序中的运用浅析-nk_ysg-ChinaUnix博客 http://blog.chinaunix.net/uid-22476414-id-3286638.html 这个目录的文章转载fr ...

  8. PHP程序中的redis一些写法

    <?php /** * 以下均要先链接好redis */ sdk\libs\RedisHelper::connect("s1")->keys('*'); //这个是获取 ...

  9. ubuntu下使用锐捷校园网

    前言           以下内容是个人学习之后的感悟,转载请注明出处~ 1.首先下载锐捷Linux版本,然后解压缩后,有个rjsupplicant.sh这个脚本文件,于是按照README做了,终端中 ...

  10. Beyond Compare 简体版+注册码

    Beyond Compare 3.3.4.14431 官方简体版+注册码 查阅全文 ›