题目大意:

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

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

直接暴力需要。

但是可以进行优化。

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

则答案为



于是可以优化到。

#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. spring容器启动过程

    1.AbstractApplicationContext的prepareRefresh()方法调用. 2.XmlBeanDefinitionReader的loadBeanDifinitions(Bea ...

  2. Android权限安全(2)给基本组件自定义权限(以activity为例)

    给基本组件自定义权限(以activity为例) 1.有访问权限的activity的定义端 1.1定义权限 <permission android:name="com.example.f ...

  3. JAVA题 矩形

    package com.lo; public class juxing { private double chang; private double kuan; public double getCh ...

  4. Topic Model

    Topic Model 标签(空格分隔): 机器学习 \(\Gamma\)函数 \(\Gamma\)函数可以看做是阶乘在实数域上的推广,即: \(\Gamma(x) = \int_{0}^{+\inf ...

  5. Java_一些特殊的关键字详(?)解

    1. native. 在看JDK源码时,想知道Math包里比如cos, sin等函数是如何实现的(猜想的是用他们在0点的泰勒展开式近似),但是打开之后却发现只有一个函数声明,并且有关键字native, ...

  6. JAVA开发--[二维码名片生成系统]

    上个月学校有个软件创新杯,最近看了网上很火的二维码比较不错.参考了国内国外一些技术文章,发现国外的确实好很多. 用的是QRcode包来实现的,基本常见的功能全部实现了. 因为刚学2个月,部分做得不是很 ...

  7. CUBRID学习笔记 1 简介 cubrid教程

    CUBRID 是一个全面开源,且完全免费的关系数据库管理系统.CUBRID为高效执行Web应用进行了高度优化,特别是需要处理大数据量和高并发请求的复杂商务服务.通过提供独特的最优化特性,CUBRID可 ...

  8. mouseover和mouseenter的区别

    mouseover和mouseenter都是鼠标事件. mouseover事件,当鼠标穿过被选元素的时候,若此元素有子元素,子元素也会被触发此事件.即是使用mouseover事件,会多次触发此元素. ...

  9. C运行时的数据结构

    本文描述一下:C运行时的数据结构,相关的段,压栈等 unix默认的编译器会将编译生成的文件默认命名为a.out 目标文件和可执行文件可以有几种不同的格式,所有这些不同格式具有一个共同的概念,那就是段. ...

  10. Switch用法

    package com.cz.test; public class SwitchExample1 { /** * @param args */ public static void main(Stri ...