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. URL重写

    http://localhost:37977/UrlWrite.ashx?id=9URL重写成下面的访问方式,有利于SEO搜索引擎http://localhost:37977/UrlWrite-8.a ...

  2. Android xml text 预览属性

    只在 AS 中生效 xmlns:tools="http://schemas.android.com/tools" tools:text="I am a title&quo ...

  3. hdu1798(几何面积计算)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1798 题意:给出两个圆的圆心坐标与半径,求他们相交部分的大小 思路:有三种情况: 1. 两圆相离,ar ...

  4. hdu1722(gcd)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1722 题意:要使一块蛋糕既能均分给a个人,又能均分给b个人,问至少需要分成几块(不需要每块都一样大小) ...

  5. Jmeter测试JDBC

    Datebase Driver class Database URL MySQL com.mysql.jdbc.Driver jdbc:mysql://host:port/{dbname} Postg ...

  6. linux退出vi

    linux退出vi操作,可以先按“esc”,再按“:”,“x”即可,这是要保存退出. 假如是修改过的,不保存,即是:先按  :   ,然后输入  q!  回车 假如未改动,即先按  :   ,然后输入 ...

  7. siblings 使用

    //$(object).siblings().each(function () { // $(this).find("img").attr("class", & ...

  8. Linux环境下使用shell编写CGI(httpd)

    /var/www/cgi-bin/hello.sh #!/bin/bash echo "Content-type: text/html" echo "" ech ...

  9. PMP 第一章 引论

    1 项目的特点 独特性 临时性 但创造的成果一般和其特点相反. 2 什么是项目管理? 什么是项目? 项目管理就是将知识 技能 工具与技术应用于项目活动,以满足项目的要求,达到项目的目的. 项目管理通过 ...

  10. [荐]使用jQuery清空file文件域

    file是文本域,我们一般都会使用它来上传文件,在上传文件时我们需要验证,验证完成后,如果存在错误,为了防止将错误信息也上传上去,我们总是希望能够将其清空.但是在IE中,为了安全起见它是不允许我们改变 ...