zoukankan      html  css  js  c++  java
  • Codeforces 651B Beautiful Paintings【贪心】

    题意:

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

    分析:

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

    代码:

    #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;
    }
  • 相关阅读:
    Mysql多表查询
    Mysql单表查询
    初始mysql语句
    MySql安装和基本管理
    jQuery的ajax
    关于DOM操作的相关案例
    DOM介绍
    关于DOM的事件操作
    使用正则写一个计算器

  • 原文地址:https://www.cnblogs.com/Tuesdayzz/p/5758752.html
Copyright © 2011-2022 走看看