题意:

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

分析:

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

代码:

#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. 工作记录:JS正则表达式 angularjs ng-if ng-show ng-switch

    用了一下JS 正则表达式判断密码,很简单 学习了angularjs的ng-if ng-show ng-switch的区别并使用 https://www.cnblogs.com/54td/p/59743 ...

  2. Android 中保存数据到文件中

    1.在安卓开发中,会遇到保存数据到手机中以及从手机中获取数据的情况 /** * 把数据存放到手机内存中 * * @param number * @param password * @return */ ...

  3. iOS Programming Controlling Animations 动画

    iOS Programming Controlling Animations 动画 The word "animation" is derived from a Latin wor ...

  4. VUE 入坑系列 一 基础语法

    html代码 <div id="app"> {{message}} </div> JavaScript代码 var vm = new Vue({ el: & ...

  5. 新手写的一个DBCP工具类

    package com.xx.questionnaire.util.dao; import java.io.IOException; import java.sql.Connection; impor ...

  6. Leetcode_638.Shopping Offers

    https://leetcode.com/problems/shopping-offers/ In LeetCode Store, there are some kinds of items to s ...

  7. CLUSTER - 根据一个索引对某个表集簇

    SYNOPSIS CLUSTER indexname ON tablename CLUSTER tablename CLUSTER DESCRIPTION 描述 CLUSTER 指示PostgreSQ ...

  8. WPF小记 -- 使用Path自己画图标,点击命中(焦点)丢失问题

    在Template中,Path外面的Grid需添加Background属性值.否则点击范围会受限制,例如:Click,在RadioButton的Height和With范围内点击,命中率<1. & ...

  9. CAD参数绘制圆(com接口)

    CAD绘制图像的过程中,画圆的情况是非常常见的,用户可以设置圆的圆心位置及半径属性. 主要用到函数说明: _DMxDrawX::DrawCircle 绘制一个圆.详细说明如下: 参数 说明 DOUBL ...

  10. 单文件组件.vue---父子组件通信

    每一个.vue 文件就是一个 组件,组件和组件相互组合,就成了一个应用,这就涉及到的组件和组件之间的通信,最常用的就是父子之间的通信.在vue 中, 在一个组件中通过 import 引入另一个组件,这 ...