题目大意:

给定集合,对于任意一个的排列,记,求。

很明显每次搞出一个长度为的最长上升序列,然后把元素给删掉,答案增加。

直接暴力需要。

但是可以进行优化。

设有个,将个数从小到大排序,记为长度为的数组。

则答案为



于是可以优化到。

#include <cstdio>
#include <cctype>
#include <algorithm>
using namespace std;

const int T=1001;

int n;
int a[T],len;

inline int read(void)
{
    int x=0; char c=getchar();
    for (;!isdigit(c);c=getchar());
    for (;isdigit(c);c=getchar()) x=x*10+c-'0';
    return x;
}

int main(void)
{
    n=read();
    for (int i=1;i<=n;i++) a[read()]++;
    printf("%d\n",n-*max_element(a,a+T));
    return 0;
}

【CodeForces 651B】Beautiful Paintings 排序+贪心的更多相关文章

  1. Codeforces 651B Beautiful Paintings【贪心】

    题意: 给定序列,重新排序,使严格上升的子序列最多.求这些子序列总长度. 分析: 贪心,统计每个元素出现次数,每次从剩余的小的开始抽到大的,直到不再剩余元素. 代码: #include<iost ...

  2. codeforces 651B Beautiful Paintings

    B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standa ...

  3. CodeForces 651B Beautiful Paintings 贪心

    A. Joysticks time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  4. Codeforces Round #345 (Div. 2)——B. Beautiful Paintings(贪心求上升序列个数)

    B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standa ...

  5. codeforce 651B Beautiful Paintings

    题意:后一个比前一个大就加一,问最大次数. #include<cstdio> #include<cstring> #include<algorithm> #incl ...

  6. [刷题codeforces]651B/651A

    651B Beautiful Paintings 651A Joysticks 点击可查看原题 651B是一个排序题,只不过多了一步去重然后记录个数.每次筛一层,直到全为0.从这个题里学到一个正确姿势 ...

  7. codeforces 651B B. Beautiful Paintings

    B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standa ...

  8. Codeforces Round #345 (Div. 2) B. Beautiful Paintings 暴力

    B. Beautiful Paintings 题目连接: http://www.codeforces.com/contest/651/problem/B Description There are n ...

  9. Codeforces 651 B. Beautiful Paintings

    B. Beautiful Paintings   time limit per test 1 second memory limit per test 256 megabytes input stan ...

随机推荐

  1. CentOS 6.3下源码安装LAMP(Linux+Apache+Mysql+Php)环境

    一.简介 什么是LAMP    LAMP是一种Web网络应用和开发环境,是Linux, Apache, MySQL, Php/Perl的缩写,每一个字母代表了一个组件,每个组件就其本身而言都是在它所代 ...

  2. CAShapeLayer

    之前讲过CALayer动画相关知识,再来看看更加复杂的CAShapeLayer相关的动画知识. 普通CALayer在被初始化时是需要给一个frame值的,这个frame值一般都与给定view的boun ...

  3. Undefined symbols for architectureIOS

    IOS问题解决. 现在进行老项目的编译,发现不能编译. 经过各种盲目查询,找个几个方案. 1.builde setting修改编译方式. 2.Builde Phases(修改). 2.1.库. 2.1 ...

  4. android sdk 国内镜像地址

    启动 Android SDK Manager ,打开主界面,依次选择「Tools」.「Options...」,弹出『Android SDK Manager - Settings』窗口: 在『Andro ...

  5. Cheatsheet: 2013 06.01 ~ 06.22

    .NET Git for Visual Studio and .NET developers How to download multiple files concurrently using Web ...

  6. Hadoop分布式部署——要点

    这里只记录几个要点,比较容易出问题的地方. 1.各服务器必须有相同的用户(便于使用相同的用户ssh登录)2.ssh互通,配置无密码登录ssh-keygen -t rsa,将id_rsa.pub的内容相 ...

  7. python 中类方法@classmethod

    classmethod是用来指定一个类的方法为类方法,没有此参数指定的类的方法为实例方法,使用方法如下: class C: @classmethod def f(cls, arg1, arg2, .. ...

  8. Android——例子:简单计算器

    今天没事干,做了个单击事件的练习. 截图如下:(一个小小的计算器) XMl文件中的代码: <LinearLayout xmlns:android="http://schemas.and ...

  9. iOS - OC Struct 结构体

    1.结构体的定义与调用 // 定义结构体类型 // 结构体类型名为 MyDate1 struct MyDate1 { int year; int month; int day; }; // 定义结构体 ...

  10. Facebook内部分享:25个高效工作的小技巧

    Facebook内部分享:25个高效工作的小技巧 Facebook 内部分享:不论你如何富有,你都赚不到更多的时间,你也回不到过去.没有那么多的假如,只有指针滴答的时光飞逝和你应该好好把握的现在,以下 ...