1346. Intervals of Monotonicity

Time limit: 1.0 second
Memory limit: 64 MB
It’s well known that a domain of any continuous function may be divided into intervals where the function would increase monotonically or decrease monotonically. A number of intervals of such a partition we will call a complexity of the partition. A complexity of a continuous function is the minimal possible complexity of partition in the domain into the monotonicity intervals.
The notion of complexity may be defined not only for continuous functions. In particular, it is applicable to the functions specified on a grid.

Input

The input contains a description of a function F, specified on a grid. The first line contains two numbers A and B — the first and the last point of the integer grid with step 1 (0 ≤ A < B ≤ 100 000). The second line contains the values table of the function F. The table consists of the integers F(A), F(A+1), …, F(B) separated with a space and/or linefeeds. All the values of the function F are in diapason from –100 000 to 100 000.

Output

Output the only number — the complexity of the function F.

Sample

input output
1 10
1 2 3 4 2 1 -1 3 6 7
3
Problem Author: Alexander Klepinin
Problem Source: USU Championship 2004
Difficulty: 358
 
题意:问一个下标从a到b的数组,它分成若干个不降序列,不升序列的最小划分数
分析:
DP啊。。。有什么特别的吗》
Up[i]表示到i结尾的不降序列
Down[i]表示到i的不升序列
转移就显然了
 
 /**
Create By yzx - stupidboy
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef double DB;
#define For(i, s, t) for(int i = (s); i <= (t); i++)
#define Ford(i, s, t) for(int i = (s); i >= (t); i--)
#define Rep(i, t) for(int i = (0); i < (t); i++)
#define Repn(i, t) for(int i = ((t)-1); i >= (0); i--)
#define rep(i, x, t) for(int i = (x); i < (t); i++)
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair
inline void SetIO(string Name)
{
string Input = Name+".in",
Output = Name+".out";
freopen(Input.c_str(), "r", stdin),
freopen(Output.c_str(), "w", stdout);
} inline int Getint()
{
int Ret = ;
char Ch = ' ';
bool Flag = ;
while(!(Ch >= '' && Ch <= ''))
{
if(Ch == '-') Flag ^= ;
Ch = getchar();
}
while(Ch >= '' && Ch <= '')
{
Ret = Ret * + Ch - '';
Ch = getchar();
}
return Flag ? -Ret : Ret;
} const int N = ;
int a, b, Arr[N];
int Up[N], Down[N]; inline void Input()
{
scanf("%d%d", &a, &b);
For(i, a, b) scanf("%d", Arr + i);
} inline void Solve()
{
Up[a] = Down[a] = ;
For(i, a + , b)
{
if(Arr[i] > Arr[i - ])
{
Up[i] = min(Up[i - ], Down[i - ] + );
Down[i] = min(Up[i - ] + , Down[i - ] + );
}
else if(Arr[i] < Arr[i - ])
{
Down[i] = min(Down[i - ], Up[i - ] + );
Up[i] = min(Up[i - ] + , Down[i - ] + );
}
else
{
Up[i] = min(Up[i - ], Down[i - ] + );
Down[i] = min(Down[i - ], Up[i - ] + );
}
} int Ans = min(Up[b], Down[b]);
printf("%d\n", Ans);
} int main()
{
#ifndef ONLINE_JUDGE
SetIO("I");
#endif
Input();
Solve();
return ;
}

ural 1346. Intervals of Monotonicity的更多相关文章

  1. URAL 1346. Intervals of Monotonicity(DP)

    题目链接 错误的贪了一下,然后D了两下就过了.注意是不上升和不下降..不是上升和下降.. #include <cstring> #include <cstdio> #inclu ...

  2. 1346. Intervals of Monotonicity(dp)

    1346 简单dp #include <iostream> #include<cstdio> #include<cstring> #include<algor ...

  3. [LeetCode] Non-overlapping Intervals 非重叠区间

    Given a collection of intervals, find the minimum number of intervals you need to remove to make the ...

  4. [LeetCode] Data Stream as Disjoint Intervals 分离区间的数据流

    Given a data stream input of non-negative integers a1, a2, ..., an, ..., summarize the numbers seen ...

  5. [LeetCode] Merge Intervals 合并区间

    Given a collection of intervals, merge all overlapping intervals. For example, Given [1,3],[2,6],[8, ...

  6. POJ1201 Intervals[差分约束系统]

    Intervals Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 26028   Accepted: 9952 Descri ...

  7. Understanding Binomial Confidence Intervals 二项分布的置信区间

    Source: Sigma Zone, by Philip Mayfield The Binomial Distribution is commonly used in statistics in a ...

  8. Leetcode Merge Intervals

    Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,1 ...

  9. LeetCode() Merge Intervals 还是有问题,留待,脑袋疼。

    感觉有一点进步了,但是思路还是不够犀利. /** * Definition for an interval. * struct Interval { * int start; * int end; * ...

随机推荐

  1. AngularJS 控制器 ng-controller

    AngularJS 控制器 控制 AngularJS 应用程序的数据. AngularJS 控制器是常规的 JavaScript 对象. AngularJS 应用程序被控制器控制. ng-contro ...

  2. selenium--python如何定位一组元素并返回文本值

    from selenium import webdriverimport time a=[] #创建一个空列表用于存储查询到的元素组driver = webdriver.Firefox()driver ...

  3. MVC - 16.MVC过滤器

          filter n. 滤波器:[化工] 过滤器:筛选:滤光器 vt. 过滤:渗透:用过滤法除去   1.过滤器表   过滤器类型 接口 默认实现 描述 Action IActionFilte ...

  4. 与你相遇好幸运,Sail.js创建.sailsrc文件

    在项目根目录下创建.sailsrc文件 {  "generators": {    "modules": {}  },  "hooks": ...

  5. Window Server 2003(IIS6) 安装.net4.0遇到的问题总结

    1.Window server 2003系统原本就装了.net1.0..net2.0 ,安装.net 4.0之前,系统已经发不了一些网站,这个时候,我安装.net 4.0返现程序不能访问了,提示ser ...

  6. 【PHP构造方法和析构方法的使用】

    构造方法:__construct,析构方法:__destruct 代码示例: <?php class Person { public $name; public $age; public fun ...

  7. ytu 1061: 从三个数中找出最大的数(水题,模板函数练习 + 宏定义练习)

    1061: 从三个数中找出最大的数 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 154  Solved: 124[Submit][Status][We ...

  8. linux环境下libevent的使用

    step1:安装libevent yum install libevent step2: 代码入下: #include <sys/socket.h> #include <sys/ty ...

  9. Android中设定EditText的输入长度(转)

    如何限定Android的Text中的输入长度呢? 方法一:可以在layout xml中加上属性android:maxLength 比如: <EditText         android:id ...

  10. oracle本机登录不上dba的权限不足错误

    说明:因遇到“sqlplus / as sysdba”登录oracle时遇到权限不足(ora-01031)错误:百度到以下资料,原文链接: http://www.xifenfei.com/2011/1 ...