您的位置:首页 > 其它

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

2017-06-02 18:57 351 查看


取每一次的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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: