Dining Cows
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7584   Accepted: 3201

Description

The cows are so very silly about their dinner partners. They have organized themselves into two groups (conveniently numbered 1 and 2) that insist upon dining together in order, with group 1 at the beginning of the line and group 2 at the end. 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 ≤ 2) 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 112222 or 111122 where the cows' dining groups are sorted in ascending order by their dinner cards. Rarely he might change cards so that only one group of cows is left (e.g., 1111 or 222).

FJ is just as lazy as the next fellow. He's curious: what is the absolute minimum 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+1 describes cow i's dining preference with a single integer: Di

Output

* Line 1: A single integer that is the minimum number of cards Farmer John must change to assign the cows to eating groups as described.

Sample Input

7
2
1
1
1
2
2
1

Sample Output

2

Source

 

简单dp

比赛没做粗来,大概是脑抽了,恩,比赛就是容易脑抽,啥时候才能正常啊。。。

#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
#define ll long long
#define _cle(m, a) memset(m, a, sizeof(m))
#define repu(i, a, b) for(int i = a; i < b; i++)
#define MAXN 30005 int d[MAXN][] = {};
int cow[MAXN];
int main()
{
int n;
scanf("%d", &n);
repu(i, , n + ) scanf("%d", &cow[i]);
d[][] = d[][] = ;
d[][cow[]] = ;
repu(i, , n + )
if(cow[i] == ) {
d[i][] = d[i - ][];
d[i][] = min(d[i - ][], d[i - ][]) + ;
}
else {
d[i][] = min(d[i - ][], d[i - ][]);
d[i][] = d[i - ][] + ;
}
printf("%d\n", min(d[n][], d[n][]));
return ;
}

F-Dining Cows(POJ 3671)的更多相关文章

  1. Lost Cows POJ 2182 思维+巧法

    Lost Cows POJ 2182 思维 题意 是说有n头牛,它们身高不一但是排成了一队,从左到右编号为1到n,现在告诉你从第二号开始前面的那些牛中身高小于它的个数,一共有n-1个数.然后求出它们按 ...

  2. 二分-F - Aggressive cows

    F - Aggressive cows Farmer John has built a new long barn, with N (2 <= N <= 100,000) stalls. ...

  3. POJ 3671 Dining Cows (DP,LIS, 暴力)

    题意:给定 n 个数,让你修改最少的数,使得这是一个不下降序列. 析:和3670一思路,就是一个LIS,也可以直接暴力,因为只有两个数,所以可以枚举在哪分界,左边是1,右边是2,更新答案. 代码如下: ...

  4. poj 3671 Dining Cows (Dp)

    /* 一开始并没有想出On的正解 后来发现题解的思路也是十分的巧妙的 还是没能把握住题目的 只有1 2这两个数的条件 dp还带练练啊 ... */ #include<iostream> # ...

  5. Popular Cows (POJ No.2186)

    Description Every cow's dream is to become the most popular cow in the herd. In a herd of N (1 <= ...

  6. (连通图 缩点 强联通分支)Popular Cows -- poj --2186

    http://poj.org/problem?id=2186 Description Every cow's dream is to become the most popular cow in th ...

  7. Cows POJ - 2481 树状数组

    Farmer John's cows have discovered that the clover growing along the ridge of the hill (which we can ...

  8. POJ3671 Dining Cows

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8126   Accepted: 3441 Description The c ...

  9. F - Truck History - poj 1789

    有一个汽车公司有很多年的汽车制造历史,所以他们会有很多的车型,现在有一些历史学者来研究他们的历史,发现他们的汽车编号很有意思都是有7个小写字母组成的,而且这些小写字母具有一些特别的意义,比如说一个汽车 ...

随机推荐

  1. PostgresSql开放局域网访问

    1) 确认已经退掉所有的MASF终端和MSF GUI,然后打开PostgresSQL的启动文件在文件POSTGRESQL_START参数后面添加-h 0.0.0.0,让PostgreSQL启动时绑定到 ...

  2. ABAP Enhancement:第一部分

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  3. window.location.hash

    我们知道JavaScript中很早就提供了window.history对象,利用history对象的forward().go().back()方法能够方便实现不同页面之间的前进.后退等这种导航功能.但 ...

  4. 几个移动App测试工具

    介绍几款移动App测试的工具: 腾讯测试:http://bugly.qq.com/优测:http://utest.qq.com/fir.im测试:http://bughd.com/ 大致介绍如下: b ...

  5. STRUTS2 常用标签的使用

    <body> <h1>s:if标签的用法</h1> <s:set name="price" value="25"> ...

  6. git各种撤销操作

    撤销git add: git reset HEAD+路径 或者git reset --+路径 撤销commit: 1.回退到具体的嘻哈值 git reset --hard     2.回退后仍包含本地 ...

  7. Python学习(15)文件/IO

    目录 Python 文件I/O 打印到屏幕 读取键盘输入 打开和关闭文件 File对象属性 文件定位 重命名和删除文件 Python的目录 Python 文件I/O 本章只讲述所有基本的的I/O函数, ...

  8. 5.2 i++

    答案:第一段21,第二段12 PS:注意运算符的优先级. 答案:A

  9. iOS开发之总结

    NO.1 要孜孜不倦的学习有句话叫技多不压身,编程本来就是一个更新换代非常快的工作.每年都有新的技术出现,我认为要成为一个出色的程序员只掌握一门语言肯定是不行的.那么,要怎么选择自己的第二门,甚至第三 ...

  10. a++累加

    <!DOCTYPE html><html lang="zh-CN"><head> <meta charset="UTF-8&qu ...