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的更多相关文章
随机推荐
- Codeforces 1237F. Balanced Domino Placements
传送门 很妙的题 首先先考虑一个简化的问题,现在有一行格子让你填 你要么填一格 要么填两格 有的格子不让你填 问你填了 $a$ 个一格和填了 $b$ 个两格有多少种方案 那么显然先只考虑放两格的方案, ...
- [C#]使用BackgroudWorker刷新UI延迟的解决方法
今天使用BackgroundWorker刷新UI发生延时现象,找了好久才发现AutoResetEvent可以解决,代码如下 private void BgWorker_ProgressChanged( ...
- centos 配置rsync+inotify数据实时同步2
一.Rsync服务简介 1. 什么是Rsync 它是一个远程数据同步工具,它在同步文件的同时,可通过LAN/WAN快速同步多台主机间的文件.Rsync使用所谓的“rsync算法”来使本地和远程两个主机 ...
- 有关图片上传的相关知识input type=file,HTML5的 input:file上传类型控制
遇到项目,要求做一个影像系统,对于前端开发需要了解file的相关属性,以及如何开发.工欲善其事,必先利器嘛.度娘一阵子搜索,找资料.这年头,需要的是你解决问题的能力啊! 参考应用:https://ww ...
- ES6入门二:默认值与默认值表达式
默认值 默认值表达式 需要注意的是,这种默认值和默认表达式在IE的最新版本中仍然没有得到兼容,只能通过编译转码的方式降级到ES5使用. 一.默认值 在函数声明时可以给形参赋默认值,当调用函数时不传入或 ...
- 完美解决Uncaught SyntaxError: Unexpected end of input
Unexpected end of input 的英文意思是“意外的终止输入” 他通常表示我们浏览器在读取我们的js代码时,碰到了不可预知的错误,导致浏览器 无语进行下面的读取 通常造成这种错误的原 ...
- vue事件处理机制
<button @click="handleAdd1()">add1</button> <button @click="handleAdd2 ...
- jboss日志的自定义
最近由于想着每次调试socket接收数据情况都需要源码debug好麻烦,要是能把接收到的数据输出到一个单独的日志文件,那出问题的时候,查看问题就方便多了. log4j的日志是可以很方便自定义的,只是这 ...
- 利用 Monitor.TryEnter 来规避 .NET 线程死锁的源代码
在开发多线程的应用程序时,我们会大量用到 lock (...) {} 块.如果 lock 的对象比较多,非常容易发生死锁.死锁的发生很难预料,而且一旦发生在界面线程上,界面就不再刷新响和应用户输入:如 ...
- Linux下MySql基本操作命令
(1).切换至MySql目录下[假设MySql安装路径为:/home/mysql/bin] cd /home/mysql/bin (2).连接MySql mysql -u用户名 -p,回车后输入密码 ...