1346. Intervals of Monotonicity(dp)
简单dp

#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
using namespace std;
#define N 200010
int p[N],dp[N][];
int main()
{
int i,a,b;
scanf("%d%d",&a,&b);
for(i = ; i <= b-a+ ; i++)
scanf("%d",&p[i]);
dp[][] = ;
dp[][] = ;
for(i = ; i <= b-a+ ; i++)
{
if(p[i]>p[i-])
{
dp[i][] = min(dp[i-][]+,dp[i-][]);
dp[i][] = min(dp[i-][]+,dp[i-][]+);
}
else if(p[i]<p[i-])
{
dp[i][] = min(dp[i-][]+,dp[i-][]+);
dp[i][] = min(dp[i-][]+,dp[i-][]);
}
else
{
dp[i][] = min(dp[i-][],dp[i-][]+);
dp[i][] = min(dp[i-][],dp[i-][]+);
}
}
int ans = min(dp[b-a+][],dp[b-a+][]);
printf("%d\n",ans);
return ;
}
1346. Intervals of Monotonicity(dp)的更多相关文章
- ural 1346. Intervals of Monotonicity
1346. Intervals of Monotonicity Time limit: 1.0 secondMemory limit: 64 MB It’s well known that a dom ...
- 【LeetCode】435. Non-overlapping Intervals 解题报告(Python)
[LeetCode]435. Non-overlapping Intervals 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemi ...
- TCSRM 593 div2(1000)(dp)
Problem Statement The pony Rainbow Dash wants to choose her pet. There are N animals who want t ...
- Intervals POJ - 3680 (MCMF)
给你一些区间,每个区间都有些价值.取一个区间就能获得对应的价值,并且一个点不能覆盖超过k次,问你最大的价值是多少. 我们可以把这些区间放到一维的轴上去,然后我们可以把它看成一个需要从左到右的过程,然后 ...
- 【LeetCode】915. Partition Array into Disjoint Intervals 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/partitio ...
- TCSRM 591 div2(1000)(dp)
挺好的dp 因为有一点限制 必须任意去除一个数 总和就会小于另一个总和 换句话来说就是去除最小的满足 那么就都满足 所以是限制最小值的背包 刚开始从小到大定住最小值来背 TLE了一组数据 后来发现如果 ...
- URAL 1346. Intervals of Monotonicity(DP)
题目链接 错误的贪了一下,然后D了两下就过了.注意是不上升和不下降..不是上升和下降.. #include <cstring> #include <cstdio> #inclu ...
- 1741. Communication Fiend(dp)
刷个简单的DP缓缓心情 1A #include <iostream> #include<cstdio> #include<cstring> #include< ...
- [LeetCode]题解(python):056-Merge Intervals
题目来源 https://leetcode.com/problems/merge-intervals/ Given a collection of intervals, merge all overl ...
随机推荐
- iOS 23 种设计模式
设计模式主要分三个类型:创建型.结构型和行为型. 其中创建型有: 一.Singleton,单例模式:保证一个类只有一个实例,并提供一个访问它的全局访问点 二.Abstract Factory,抽象工厂 ...
- window对象的属性方法名造成的命名冲突
事件起因: 一次开发中需要获取一个数组的长度,写下如此代码 function func(arr){ length = arr.length; ......//相关操作 } 程序在chrome下正常运行 ...
- Ligerui Grid组件--学生信息列表
一.目录 1.多层架构+MVC+EF+AUTOFAC+AUTOMAPPER: 2.MVC中验证码的实现(经常用,记录备用) 3.Ligerui首页的快速搭建 4.Ligerui Grid组件--学生信 ...
- php多条件查询
$sql)"; if(!empty($uid)) { $sql .=" and uid= ".$uid; } if(!empty($time1) && e ...
- Python的map、filter、reduce函数 [转]
1. map函数func作用于给定序列的每个元素,并用一个列表来提供返回值. map函数python实现代码: def map(func,seq): mapped_seq = [] fo ...
- How to Enable 64-bit Processes for Enhanced Protected Mode in Internet Explorer 11 (IE11)
Information Enhanced Protected Mode (EPM) adds additional security to Protected Mode and includes ...
- Tutorial: Model
What is a model? Across the internet the definition of MVC is so diluted that it's hard to tell what ...
- Lua 简单的IO交互 和迷宫代码
function room1 () print("in room1") local move = io.read() if move == "south" th ...
- Class Object
java.lang Class Object java.lang.Object public class Object Class Object is the root of the class hi ...
- POJ 1988 Cube Stacking(带权并查集)
哈哈,一次AC. 题意:给你 1-n 编号的立方体,然后移动包含指定编号的立方体的堆移到另一个堆上边, 询问指定的编号立方体下面有多少个立方体. 思路:由于并查集是存储的是它的父亲,那么只能从父亲那里 ...