POJ 3670 Eating Together LIS最长递增子序列+二分查找 nlogn算法
来源:互联网 发布:知牛财经做主播赚钱吗 编辑:程序博客网 时间:2024/06/05 02:49
http://poj.org/problem?id=3670
Description
The cows are so very silly about their dinner partners. They have organized themselves into three groups (conveniently numbered 1, 2, and 3) that insist upon dining together. The trouble starts when they line up at the barn to enter the feeding area.
Each cow i carries with her a small card upon which is engraved Di (1 ≤ Di ≤ 3) indicating her dining group membership. The entire set of N (1 ≤ N ≤ 30,000) cows has lined up for dinner but it's easy for anyone to see that they are not grouped by their dinner-partner cards.
FJ's job is not so difficult. He just walks down the line of cows changing their dinner partner assignment by marking out the old number and writing in a new one. By doing so, he creates groups of cows like 111222333 or 333222111 where the cows' dining groups are sorted in either ascending or descending order by their dinner cards.
FJ is just as lazy as the next fellow. He's curious: what is the absolute mminimum number of cards he must change to create a proper grouping of dining partners? He must only change card numbers and must not rearrange the cows standing in line.
Input
* Line 1: A single integer: N
* Lines 2..N+1: Line i describes the i-th cow's current dining group with a single integer: Di
Output
* Line 1: A single integer representing the minimum number of changes that must be made so that the final sequence of cows is sorted in either ascending or descending order
Sample Input
513211
Sample Output
1
- POJ 3670 Eating Together LIS最长递增子序列+二分查找 nlogn算法
- poj 3670 Eating Together(最长上升子序列 lis nlogn复杂度)
- POJ 1631 Bridging signals LIS(最长递增子序列) +nlogn算法+二分查找
- POJ 3670 Eating Together(LIS+nlogn算法)
- poj 3670 Eating Together(最长不下降子序列、LIS)
- poj 3670 Eating Together LIS+二分
- 最长递增子序列 O(NlogN)算法 ( DP + 二分查找)
- 最长递增子序列LIS(动态规划+二分查找)
- POJ 3670 Eating Together(LIS)
- poj 3670 Eating Together LIS
- POJ 2533最长递增子序列O(nlogn) 算法
- POJ 3903 【最长递增子序列 NLOGN】
- 最长递增子序列 O(NlogN)算法
- 最长递增子序列 O(NlogN)算法
- 最长递增子序列 O(NlogN)算法
- 最长递增子序列 O(NlogN)算法
- 最长递增子序列 O(NlogN)算法
- 最长递增子序列 O(NlogN)算法
- HDU 1274 展开字符串
- 网站SEO优化价格误区
- MySQL 文章管理
- 阿里巴巴DBA面试题及一份答案
- 浮点数比较之我见
- POJ 3670 Eating Together LIS最长递增子序列+二分查找 nlogn算法
- NoSQL数据库探讨 - 为什么要用非关系数据库?
- IBM HACMP 系列 -- 安装和配置二
- qt qt/e configure
- AJAX的跨域访问-两种有效的解决方案
- c语言 #define 中的UL
- 插入flash(swf)代码,及flash常用的参数设置
- Asp.net MVC 3实例学习之ExtShop(四)——完成产品列表页
- use_concat导致not in时临时表不动态采样进而导致的性能问题