codeforces269B
Greenhouse Effect
Emuskald is an avid horticulturist and owns the world's longest greenhouse — it is effectively infinite in length.
Over the years Emuskald has cultivated n plants in his greenhouse, of m different plant species numbered from 1 to m. His greenhouse is very narrow and can be viewed as an infinite line, with each plant occupying a single point on that line.
Emuskald has discovered that each species thrives at a different temperature, so he wants to arrange m - 1 borders that would divide the greenhouse into m sections numbered from 1 to m from left to right with each section housing a single species. He is free to place the borders, but in the end all of the i-th species plants must reside in i-th section from the left.
Of course, it is not always possible to place the borders in such way, so Emuskald needs to replant some of his plants. He can remove each plant from its position and place it anywhere in the greenhouse (at any real coordinate) with no plant already in it. Since replanting is a lot of stress for the plants, help Emuskald find the minimum number of plants he has to replant to be able to place the borders.
Input
The first line of input contains two space-separated integers n and m (1 ≤ n, m ≤ 5000, n ≥ m), the number of plants and the number of different species. Each of the following n lines contain two space-separated numbers: one integer number si (1 ≤ si ≤ m), and one real number xi (0 ≤ xi ≤ 109), the species and position of the i-th plant. Each xi will contain no more than 6 digits after the decimal point.
It is guaranteed that all xi are different; there is at least one plant of each species; the plants are given in order "from left to the right", that is in the ascending order of their xi coordinates (xi < xi + 1, 1 ≤ i < n).
Output
Output a single integer — the minimum number of plants to be replanted.
Examples
3 2
2 1
1 2.0
1 3.100
1
3 3
1 5.0
2 5.5
3 6.0
0
6 3
1 14.284235
2 17.921382
1 20.328172
3 20.842331
1 25.790145
1 27.204125
2 sol:题意略坑,按照颜色跑一遍最长不下降子序列就好了
//给出一个实数轴,上面散布着n个点,他们是m种,问最少挪多少步能将数轴上的点分成1~m的种类顺序排列的m块。
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,m,dp[N];
struct Point
{
int Cor;
double Pos;
}P[N];
int main()
{
int i,j,ans=;
R(n); R(m);
for(i=;i<=n;i++)
{
R(P[i].Cor); scanf("%lf",&P[i].Pos);
}
P[].Cor=; dp[]=;
for(i=;i<=n;i++)
{
for(j=;j<i;j++) if(P[j].Cor<=P[i].Cor) dp[i]=max(dp[i],dp[j]+);
ans=max(ans,dp[i]);
}
Wl(n-ans);
return ;
}
/*
Input
3 2
2 1
1 2.0
1 3.100
Output
1 Input
3 3
1 5.0
2 5.5
3 6.0
Output
0 Input
6 3
1 14.284235
2 17.921382
1 20.328172
3 20.842331
1 25.790145
1 27.204125
Output
2 Input
15 5
4 6.039627
2 7.255149
2 14.469785
2 15.108572
4 22.570081
5 26.642253
5 32.129202
5 44.288220
5 53.231909
5 60.548042
4 62.386581
2 77.828816
1 87.998512
3 96.163559
2 99.412872
Output
6
*/
codeforces269B的更多相关文章
随机推荐
- MySQL 存储引擎的类型以及选择
			针对MySQL,数据最终以什么样的形式保存?以及数据保存在硬盘的什么位置? 1.MySQL的存储引擎 MySQL属于数据管理系统(DBMS),其中包括数据库,负责存储数据:还有数据库访问管理的接口系统 ... 
- [C#.net]C#如何解析json文本文件
			C#解析Json字符串,可以借助Newtonsoft.Json将Json字符串序列化为对象,再从对象中获取值 Newtonsoft.Json.JsonConvert.DeserializeObject ... 
- Selenium 基本使用
			from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.c ... 
- Struts的相关基础
			为什么要用struts? 1.该框架基予mvc的开发设计模式上的,所以拥有mvc的全部优点,他在M.V.C上都有涉及,但它主要是提供一个好的控制器和一套定制的标签库上,有mvc的一系列优点:层次分明, ... 
- js之语句——案例
			以下为js语句的案例题,虽然简单,但是里面涉及到语句的嵌套,多个参数,需要好好分析. 1.求出1-100之间所有奇/偶数之和 <script> var sum = 0; for (var ... 
- JS 中的跨域请求
			跨域请求并不仅仅只是 Ajax 的跨域请求,而是对于一个页面来说,只要它请求了其他域名的资源了,那么这个过程就属于跨域请求了. 比如,一个带有其他域名的 src 的 <img> 标签,以及 ... 
- python之时间日期calendar
			calendar是与日历相关的模块,calendar模块文件里定义了很多类型,主要有Calendar,TextCalendar以及HTMLCalendar类型.其中,Calendar是TextCale ... 
- Windows地址栏的妙用
			主角: 它就是windows自带的一个小工具->地址栏,可以通过在任务栏右键选择工具栏-地址栏添加使用. 妙用: 一.打开文件 使用方法:D:\Temp(文件路径) 小提示:快速进入回收站:Re ... 
- 读micro8的一些记录与思考
			最近做了一段时间的攻击,个人对于整个攻击链相对来说还是比较熟悉.看了侯师傅的文章还是学到一些,做个备忘. 1. 
- 使用Django开发简单接口:文章增删改查
			目录 1.一些准备工作 安装django 创建django项目 创建博客应用(app) 2.models.py 3.django admin 登录 创建超级用户 4.修改urls.py 5.新增文章接 ... 
