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;
    }
  • 相关阅读:
    Uboot USB模式(RK3288变砖头的解决办法)
    C++ 解析一
    C++基础
    shell脚本分析二
    ASCII
    POJ 1970 The Game (DFS)
    PoJ1979 Red and Black (DFS)
    UVA 572 Oil Deposits (DFS)
    打印日历
    求第N个素数
  • 原文地址:https://www.cnblogs.com/Tuesdayzz/p/5758752.html
Copyright © 2011-2022 走看看