题意:

给定序列,重新排序,使严格上升的子序列最多。求这些子序列总长度。

分析:

贪心,统计每个元素出现次数,每次从剩余的小的开始抽到大的,直到不再剩余元素。

代码:

#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 1005;
int a[maxn];
int m[maxn];
int main (void)
{ int n;cin>>n;
for(int i = 0; i < n; i++){
cin>>a[i];
}
sort(a, a + n);
int j = 0;
int maxm = 0;
for(int i = 1; i < n; i++){
if(a[j]!=a[i])
a[++j] = a[i];
else{
m[a[i]]++;
maxm = max(maxm, m[a[i]]);
}
}
int cnt, res = 0;
for(int i = 0; i < maxm; i++){
cnt = 0;
for(int k = 0; k <= j; k++){
if(m[a[k]]>=1){
cnt++;
m[a[k]]--;
}
}
if(cnt > 1) res += cnt - 1;
}
cout<<j + res<<endl;
}

Codeforces 651B Beautiful Paintings【贪心】的更多相关文章

  1. CodeForces 651B Beautiful Paintings 贪心

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

  2. codeforces 651B Beautiful Paintings

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

  3. codeforce 651B Beautiful Paintings

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

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

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

  5. codeforces 651B B. Beautiful Paintings

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

  6. 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 ...

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

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

  8. Codeforces 651 B. Beautiful Paintings

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

  9. codeforces 704B - Ant Man 贪心

    codeforces 704B - Ant Man 贪心 题意:n个点,每个点有5个值,每次从一个点跳到另一个点,向左跳:abs(b.x-a.x)+a.ll+b.rr 向右跳:abs(b.x-a.x) ...

随机推荐

  1. AJPFX关于File类复习

    file是一个路径,分为相对路径(eclipse)和绝对路径:1.构造方法有:File(String pathname ),File(String parent ,String child),File ...

  2. FastDFS的简单使用

    互联网中有海量的文件,比如电商网站有海量的图片文件,视频网站有海量的视频文件,如果使用传统的模式上传文件,肯定是不可取的.因此需要使用第三方服务器来存储图片 . 一.FastDFS简介 ​ FastD ...

  3. 纯css实现的三级水平导航菜单

    vscode练习使用开发纯css的三级水平导航菜单.先上图: 1.html5布局 <html> <head> <meta charset="UTF-8" ...

  4. QT入门学习

    第一个QT程序 #include<QApplication> #include<QDialog> #include<QLabel> #include<QTex ...

  5. ibatis 的sqlMap 的xml 关注点

    1.当有特殊字符时候需要保持原状 eg:特殊字符  <> 错误:t.name<>' '   会报The content of elements must consist of ...

  6. 用16G内存在Java

    用16G内存在Java Map中处理30亿对象 在一个下雨的夜晚,我在思考Java中内存管理的问题,以及Java集合对内存使用的效率情况.我做了一个简单的实验,测试在16G内存条件下,Java的Map ...

  7. c++ 数组长度

    数组长度求解 sizeof template <class T>int getArrayLen(T &array){ return (sizeof(array) / sizeof( ...

  8. 网页显示403. That’s an error的解决方法。

    使用Go*gent打开网页,经常出现403. That’s an error.下面是解决的方法.   方法/步骤   一.打开Go*gent的文件目录.不知道找文件目录的,可以在桌面上右键点击Go*g ...

  9. Hadoop架构模型

    1.hadoop 1.x架构模型:分布式文件存储系统:HDFSNameNode(主节点:管理元数据) secondaryNameNode(作用是合并元数据信息,辅助NameNode管理元数据信息)Da ...

  10. python selenium定位总结(转)

    转自:http://www.cnblogs.com/yufeihlf/p/5717291.html 父子定位元素 查找有父亲元素的标签名为span,它的所有标签名叫input的子元素 find_ele ...