题意:

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

分析:

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

代码:

#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. [BZOJ1257][CQOI2007]余数之和sum 数学+分块

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1257 题目所求为$$Ans=\sum_{i=1}^nk%i$$ 将其简单变形一下$$Ans ...

  2. mac系统 usr/ 目录下无法新建文件夹???

    这个问题是在操作mongodb的时候遇到的,很苦恼.目前已经解决,将解决方法分享给各位遇到同样问题的你们. 1.重启电脑,开始关机就立马按住command+R,进入macOS恢复功能界面,进入的时间可 ...

  3. 微信小程序组件解读和分析:十四、slider滑动选择器

    slider滑动选择器组件说明: 滑动选择器. slider滑动选择器示例代码运行效果如下: 下面是WXML代码: [XML] 纯文本查看 复制代码 ? 01 02 03 04 05 06 07 08 ...

  4. 浅谈网上的zoomlistview存在的问题

    最近项目主要是做一个类似wps文档阅历的功能,以列表的形式显示文档,并且需要实现缩放平移.而网上关于此类功能的实现主要是通过自定义的listview实现的,类名为ZoomListView. 网上的zo ...

  5. 分享div、text、Box Shadow(阴影)演示及代码的页面

    附图: 直接上链接:www.css88.com/tool/css3Preview/Box-Shadow.html

  6. 学习 微信小程序 大神不要笑

  7. bat 时间 的运算与提取

    比如在系统中date这个环境变量的值为 -- 星期六 年------%date:~,% 表示从左向右指针向右偏0位,然后从指针偏移到的位置开始提取4位字符,结果是2011 月------%date:~ ...

  8. QQ感叹号是什么鬼?原来是服务器波动,腾讯官方来辟谣了

    今天晚上很多网友在用QQ发送消息的时候发现,自己发送的消息一直是感叹号❗到底是怎么回事呢?是消息都发不出去了吗?马浩周通过手机测试后发现,其实消息是可以发出去的,而官方手机QQ出来已经通知了,是服务器 ...

  9. leetcode_378. Kth Smallest Element in a Sorted Matrix_堆的应用

    Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth ...

  10. freopen()重定向的打开和关闭

    freopen函数 功能 使用不同的文件或模式重新打开流,即重定向. 实现重定向,把预定义的标准流文件定向到由path指定的文件中.(直观感觉/实际操作都像是把文件定向到流,难道是说,对流来说就是重定 ...