TopCoder:ZigZag(动态规划--最长非降子序列)

本文介绍了如何利用动态规划解决TopCoder上的ZigZag序列问题。ZigZag序列定义为正负差异交替的数字序列,例如1,7,4,9,2,5。目标是找到给定整数序列的最长ZigZag子序列。解题思路类似于最长非降子序列,通过维护两个数组down[]和up[],分别记录当前数字后面比它小和大的序列长度,根据比较结果更新这两个数组,最终找到最长序列的长度。" 109236309,10068608,Python内置函数详解:69个函数全解析,"['Python', '编程语言', '函数库']
摘要由CSDN通过智能技术生成

看动态规划的题 在topcoder里看的这道题就来练练手

Problem Statement 

A sequence of numbers is called a zig-zag sequence if the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with fewer than two elements is trivially a zig-zag sequence.


For example, 1,7,4,9,2,5 is a zig-zag sequence because the differences (6,-3,5,-7,3) are alternately positive and negative. In contrast, 1,4,7,2,5 and 1,7,4,5,5 are not zig-zag sequences, the first because its first two differences are positive and the second because its last difference is zero.


Given a sequence of integers, sequence, return the length of the longest subsequence of sequence that is a zig-zag sequence. A subsequence is obtained by deleting some number of elements (possibly zero)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值