题目链接:https://codeforces.com/contest/1064/problem/C
题意:
给你一个长度为n的由小写字母组成的字符串,让你对它进行重新排列,使得它的回文子串是最多的。
思路:
对样例进行操作发现,当把所有的相同的字母放在一起的时候回文子串就是最多的,因为这个时候每个字母都可以产生尽可能多的贡献。比如样例1,排列成oooll时回文子串最多。
代码:
#define push_back pb
#define make_pair mk
#define rd read()
#define mem(a,b) memset(a,b,sizeof(a))
#define bug printf("*********\n");
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define FIN freopen(D://code//in.txt", "r", stdin);
#define debug(x) cout<<"["<<x<<"]" <<endl;
#define IO ios::sync_with_stdio(false),cin.tie(0);
#pragma comment(linker,"/STACk:1024000000,1024000000")
//#include<bits/stdc++.h>
#include<time.h>
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<cmath>
#include<map>
#include<algorithm>
#include<string>
#include<string.h>
#include<set>
#include<queue>
#include<stack>
#include<functional>
using std::pair;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
//const double PI=acos(-1);
const int maxn = 1e5 + 10;
const int maxm = 2e3 + 10;
const int mod = 1000000007;
const int inf = 0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const double dinf=1e20;
const double eps=1e-8;
using namespace std;
ll read() {
ll X = 0, p = 1; char c = getchar();
for(; c > '9' || c < '0'; c = getchar()) if(c == '-') p = -1;
for(; c >= '0' && c <= '9'; c = getchar()) X = X * 10 + c - '0';
return X * p;
}
int sgn(double x)
{
if(fabs(x)<eps) return 0;
if(x<0) return -1;
return 1;
}
//*************************************************************
int main()
{
int n;
string s;
cin>>n>>s;
int num[30];
mem(num,0);
for(int i=0;i<n;i++)
{
num[s[i]-'a']++;
}
for(int i=0;i<26;i++)
{
// cout<<num[i]<<endl;
for(int j=0;j<num[i];j++)
{
cout<<char(i+'a');
}
}
cout<<endl;
}