题目大意:

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

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

直接暴力需要。

但是可以进行优化。

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

则答案为



于是可以优化到。

#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. C#json 解析

    Json样例一: string jsonText= {Code)\/)\/"}}} JObject jo = JObject.Parse(jsonText); string strCode= ...

  2. mvc ==》json url

    mvc ==>json 这也是.net 4.0 与4.5的区别,4.0 自带 ,而4.5 则要自己加上去,微软说是 當然,最簡單的應變措施就是直接把這段設定加回去,不過,加回去之前請三思,這條設 ...

  3. MVC4 经典增删改查详情demo

    MVC4 经典增删改查详情demo 源码 不解释 Mvc4增删改查详情Demo.7z public ActionResult Detail(int? id)  {    ViewData.Model ...

  4. dubbo源码之三-模块依赖

    dubbo版本:2.5.4 参照:http://www.tuicool.com/articles/qIN36ff

  5. centos Linux 统计某个文件夹占用空间大小

    转载自 http://www.07net01.com/linux/centos_Linux_tongjimougewenjianjiazhanyongkongjiandaxiao_12510_1346 ...

  6. 将linux默认python升级到2.7.4版本

    第一步:下载python2.7.4版本源码: wget http://python.org/ftp/python/2.7.4/Python-2.7.4.tgz 解压文件 [aa@localhost ~ ...

  7. SQL数据库约束行为---防止数据漏填

    防止有些该填的没有填:一.非空约束不能为NULL.操作:在表的设计界面中“允许NULL值”中的复选框去掉. 二.默认值.如果不给列赋值的话,会使用默认值填上.操作:在表的设计界面,选择相应的列,在下面 ...

  8. 在包a中新建一个类A,在类A中有一个int add(int m)方法,用来求1+2+…+m 的和。在包b中新建一个类B,在类B中有一个int cheng(int n)方法,用来求n! 的结果。在包c中新建一个主类C,调用A、B中的方法输出1+2+…+30的和, 以及5!的计算结果。

    package a; public class A { public void add(int m) { int sum=0; for (int i = 1; i <=m; i++) { sum ...

  9. 插入中文错误ERROR 1406 (22001): Data too long for column 'name' at row 1

    1.在导入数据前执行以下命令即可:set SESSION sql_mode=''; 通过设置sql_mode变量更改模式.linux下安装完mysql后,默认的sql-mode值是空,在这种情形下my ...

  10. hdu 4223 Dynamic Programming?

    Dynamic Programming? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...