Problem D. What a Beautiful Lake dp
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的更多相关文章
- hihocoder 1425What a Beautiful Lake(实验专用)
Problem D. What a Beautiful Lake Description Weiming Lake, also named "Un-named Lake", is ...
- hihoCoder 1425 : What a Beautiful Lake(美丽滴湖)
hihoCoder #1425 : What a Beautiful Lake(美丽滴湖) 时间限制:1000ms 单点时限:1000ms 内存限制:256MB Description - 题目描述 ...
- Problem D: 勤奋的涟漪2 dp + 求导
http://www.gdutcode.sinaapp.com/problem.php?cid=1049&pid=3 dp[i][state]表示处理了前i个,然后当前状态是state的时候的 ...
- Aizu 2305 Beautiful Currency DP
Beautiful Currency Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest ...
- 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 ...
- Codeforces 713C Sonya and Problem Wihtout a Legend(单调DP)
[题目链接] http://codeforces.com/problemset/problem/713/C [题目大意] 给出一个数列,请你经过调整使得其成为严格单调递增的数列,调整就是给某些位置加上 ...
- (中等) HDU 5293 Tree chain problem,树链剖分+树形DP。
Problem Description Coco has a tree, whose vertices are conveniently labeled by 1,2,…,n.There are ...
- Codeforces 1085G(1086E) Beautiful Matrix $dp$+树状数组
题意 定义一个\(n*n\)的矩阵是\(beautiful\)的,需要满足以下三个条件: 1.每一行是一个排列. 2.上下相邻的两个元素的值不同. 再定义两个矩阵的字典序大的矩阵大(从左往右从上到下一 ...
- Problem D: 乌龟棋【四维dp】
Problem D: 乌龟棋 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 24 Solved: 15[Submit][Status][Web Boa ...
随机推荐
- 如何修改Windows的默认安装路径
运行中输入regedit打开注册表编辑器 展开注册表“HKEY_LOCAL_MACHINE\Software\Microsoft\ Windows\ CurrentVersion”分支, 在窗口的右侧 ...
- hdu-4857 逃生(拓扑序)
题目链接: 逃生 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Proble ...
- Android终端管理器删除文件夹
终端管理器删除文件夹不能用网上提供的: rm -rf 文件夹名 而要用: rm -r 文件夹名. http://blog.csdn.net/enhancing/article/details/8490 ...
- python 文件与文件夹常见操作以及os.walk的用法
文件操作: In [34]: import os In [35]: os.rename("hello[复件].py","hello111.py") ...
- TypeError: Unexpected keyword argument passed to optimizer: amsgrad原因及解决办法
原因: AMSgrad只支持2017年12月11日后发行的keras版本 解决办法: pip install --upgrade keras
- python-pycharm 设置默认代码及注释
pycharm
- P4147玉蟾宫——最大子矩阵
悬线法裸题. 代码如下: #include<iostream> #include<cstdio> #include<cstring> using namespace ...
- Android开发者的四大工具
1. Basic4Android Basic4Android是Android平台上一个简单而又强大的可视化快速应用开发工具,它可被用来开发和测试数据库通信,甚至可以被用来开发2D的即时游戏! 主要特性 ...
- AngularJS系统学习之Directive(指令)
本文转自https://www.w3ctech.com/topic/1612 原文作者: Nicolas Bevacqua 原文:AngularJS’ Internals In Depth, Part ...
- 使用 Git 命令去管理项目的版本控制(二)
参考 上一篇 完成本篇博客,本篇为作者原创,仅供学习参考. 本篇博文在上一篇的基础上这里记录了我的一个小模拟练习.本篇作为自己的学习笔记,也意在方便其他人的学习使用,达到分享目的.下面主要是操作截图 ...