【贪心】17.6.1 优雅的序列 题解

来源:互联网 发布:数控机床编程技术 编辑:程序博客网 时间:2024/06/10 00:34

这里写图片描述
取每一次的lis就可以了

#include <iostream>#include <cstdio>#include <algorithm>using namespace std;const int maxn = 1e5+5;int n,tot,ans;int a[maxn],b[maxn];template <class T> inline void read(T &x) {    int flag = 1; x = 0;    char ch = getchar();    while(ch <  '0' || ch >  '9') { if(ch == '-')  flag = -1; ch = getchar(); }    while(ch >= '0' && ch <= '9') { x = (x<<1)+(x<<3)+ch-'0'; ch = getchar(); }    x *= flag;}int main() {    freopen("grace.in","r",stdin);    freopen("grace.out","w",stdout);    read(n);    for(int i = 1; i <= n; i++) read(a[i]);    sort(a+1, a+1+n);    for(int i = 1; i <= n; i++)        if(a[i] == a[i-1]) b[tot]++;        else b[++tot]++;    sort(b+1, b+1+tot);    for(int i = 1; i <= tot; i++) if(b[i] != b[i-1]) ans += (tot-i)*(b[i]-b[i-1]);    printf("%d\n",ans);    return 0;}
原创粉丝点击