URAL 1346. Intervals of Monotonicity(DP)
错误的贪了一下,然后D了两下就过了。注意是不上升和不下降。。不是上升和下降。。
#include <cstring>
#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;
#define INF 100000000
int p[];
int dp[];
int o1[];
int o2[];
int main()
{
int a,b,i,n;
scanf("%d%d",&a,&b);
n = b - a + ;
for(i = ;i <= n;i ++)
scanf("%d",&p[i]);
o1[] = o2[] = ;
for(i = ;i <= n;i ++)
{
if(p[i] >= p[i-])
o1[i] = o1[i-];
else
o1[i] = i;
if(p[i] <= p[i-])
o2[i] = o2[i-];
else
o2[i] = i;
}
for(i = ;i <= n;i ++)
{
dp[i] = min(dp[o1[i]-],dp[o2[i]-]) + ;
}
printf("%d\n",dp[n]);
return ;
}
URAL 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 ...
- 1346. Intervals of Monotonicity(dp)
1346 简单dp #include <iostream> #include<cstdio> #include<cstring> #include<algor ...
- URAL 1658. Sum of Digits(DP)
题目链接 隔了一年零三个月,重新刷URAL,这题挺麻烦的输出路径.输出路径挺扯的,乱写了写乱改改就A了...我本来想用很靠谱,记录每一条路径的,然后输出最小的,结果Tle,然后我使劲水水又过了一组,发 ...
- URAL 1776 C - Anniversary Firework DP
C - Anniversary FireworkTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/c ...
- Ural 1073 Square Country (DP)
题目地址:Ural 1073 DP水题.也能够说是背包. #include <iostream> #include <cstdio> #include <string&g ...
- bzoj 1814 Ural 1519 Formula 1 插头DP
1814: Ural 1519 Formula 1 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 942 Solved: 356[Submit][Sta ...
- 【BZOJ1814】Ural 1519 Formula 1 插头DP
[BZOJ1814]Ural 1519 Formula 1 题意:一个 m * n 的棋盘,有的格子存在障碍,求经过所有非障碍格子的哈密顿回路个数.(n,m<=12) 题解:插头DP板子题,刷板 ...
- CodeForces - 367E:Sereja and Intervals(组合数&&DP)
Sereja is interested in intervals of numbers, so he has prepared a problem about intervals for you. ...
- Ural 1183 Brackets Sequence(区间DP+记忆化搜索)
题目地址:Ural 1183 最终把这题给A了.. .拖拉了好长时间,.. 自己想还是想不出来,正好紫书上有这题. d[i][j]为输入序列从下标i到下标j最少须要加多少括号才干成为合法序列.0< ...
随机推荐
- Linux Shell 高级编程技巧4----几个常用的shell脚本例子
4.几个常用的shell脚本例子 4.0.在写脚本(同样适用在编程的时候),最好写好完善的注释 4.1.kill_processes.sh(一个杀死进程的脚本) #!/bin/bash c ...
- Jmeter在restful风格接口测试中的应用
1.如何下载安装 官网下载,一个压缩包apache-jmeter-3.0.zip,解压即可,打开bin目录下jmeter.bat即可打开软件. 2.熟悉界面 3.实际案例 测试restful风格接口 ...
- poj 1002:487-3279(水题,提高题 / hash)
487-3279 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 236746 Accepted: 41288 Descr ...
- Ubuntu / Win7 安装db2 v10.5
抓紧下载v10.5fp1_linuxx64_expc.tar.gz到~/Downloads/java_softcd java_softtar xf v10.5fp1_linuxx64_expc.tar ...
- 在WPF中使用CefSharp嵌入浏览器
日常开发中,我们需要将一些Web页面嵌入到桌面客户端软件中.下面我们使用CefSharp嵌入浏览器来实现. 首先先介绍一下CefSharp嵌入式浏览器,它是基于Google浏览器的一个组件,我们可以在 ...
- zoj 3888 线段树 ***
卡n^2,用线段树降到nlogn 记录每个点上所覆盖线段的次小值,保证能有两条路径能走 #include<cstdio> #include<iostream> #include ...
- Android 第3方控件一览表
1 UnSlideListView 解决在ScrollView的无法正常显示的问题 例子在“真好项目”中“NGDetailActivity”.“HKcfqjActivity”.
- C# 对象转换为byte[] ,byte[]还原对象
/// <summary> /// 将一个object对象序列化,返回一个byte[] /// </summary> /// <param name ...
- springMVC核心配置文件样例
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- 第一个vs2013控制台程序
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...