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;
    }
  • 相关阅读:
    实验
    概率与期望
    2020CSP-S模板
    洛谷:P2538 [SCOI2008]城堡
    洛谷P1731 生日蛋糕
    洛谷 P1180 石子合并
    洛谷 P2831 愤怒的小鸟
    浅谈状压DP
    浅谈线段树
    LCA-树链剖分
  • 原文地址:https://www.cnblogs.com/Tuesdayzz/p/5758752.html
Copyright © 2011-2022 走看看