嘟嘟嘟

只要将每一种字母放一块输出就行了。

证明1:比如 1 2 3 4 5 6,那么这个序列对答案的贡献分别是1和5,2和4 ,3和6……如果重新排列成x x x x o o,会发现对          x x o x x o  答案的贡献不变,所以得证。

证明2:字母ai有xi个,那么对答案的最大贡献为xi * (xi - 1) / 2,重排后能达到理论上界,所以为最优解。   

 #include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define rg register
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-;
const int maxn = 1e5 + ;
inline ll read()
{
ll ans = ;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) last = ch, ch = getchar();
while(isdigit(ch)) ans = (ans << ) + (ans << ) + ch - '', ch = getchar();
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < ) x = -x, putchar('-');
if(x >= ) write(x / );
putchar(x % + '');
} int n, a[];
char c[maxn]; int main()
{
n = read(); scanf("%s", c);
for(int i = ; i < n; ++i) a[c[i] - 'a']++;
for(int i = ; i <= ; ++i)
if(a[i]) while(a[i]--) putchar(i + 'a');
enter;
return ;
}

CF1063A Oh Those Palindromes的更多相关文章

  1. cf1063A Oh Those Palindromes (贪心)

    给一些字符 求它们能拼成的字符串 的回文子串的个数最大值 对应的那个字符串 就是把相同的都放一起是最优的,排下序就行了... #include<bits/stdc++.h> #define ...

  2. CF1063A 【Oh Those Palindromes】

    考虑在一个部分串中加入字符使得最终构造的串回文子串最多的方案 考虑简单情况,对于只含一种元素的串,我们要插入其他元素 记原有元素为$a$,新加元素为$b$ 考虑$b$的最优插入位置 原串$aaaa.. ...

  3. UVA - 11584 Partitioning by Palindromes[序列DP]

    UVA - 11584 Partitioning by Palindromes We say a sequence of char- acters is a palindrome if it is t ...

  4. hdu 1318 Palindromes

    Palindromes Time Limit:3000MS     Memory Limit:0KB     64bit                                         ...

  5. dp --- Codeforces 245H :Queries for Number of Palindromes

    Queries for Number of Palindromes Problem's Link:   http://codeforces.com/problemset/problem/245/H M ...

  6. Dual Palindromes

    Dual PalindromesMario Cruz (Colombia) & Hugo Rickeboer (Argentina) A number that reads the same ...

  7. ytu 1940:Palindromes _easy version(水题)

    Palindromes _easy version Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 47  Solved: 27[Submit][Statu ...

  8. 回文串+回溯法 URAL 1635 Mnemonics and Palindromes

    题目传送门 /* 题意:给出一个长为n的仅由小写英文字母组成的字符串,求它的回文串划分的元素的最小个数,并按顺序输出此划分方案 回文串+回溯:dp[i] 表示前i+1个字符(从0开始)最少需要划分的数 ...

  9. UVA 11584 一 Partitioning by Palindromes

    Partitioning by Palindromes Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %l ...

随机推荐

  1. 有意思的MySQL之最

    写在前面 在平时工作中特别是架构设计阶段,咨询量最多的也就是MySQL之最了,在不经意间发现原来MySQL手册里面已经列举了,顺手拿来翻译下,如果有翻译错误或者不当的地方,欢迎批评指正. 最大和最小 ...

  2. 使用Myeclipse进行简单webservice开发的示例

    (转) http://blog.csdn.net/changhenshui1990/article/details/70142371 前言:朋友们开始以下教程前,请先看第五大点的注意事项,以避免不必要 ...

  3. Javascript基础系列之(五)条件语句(逻辑操作符)

    javascript和其它语言一样,逻辑运算主要包括 与运算&& ,或运算 II  和非运算 ! 与运算(&&)是指两个条件都为true时,整个表达式为true,或运算 ...

  4. 【原创】Hadoop的IO模型(数据序列化,文件压缩)

    数据序列化 我们知道,数据在分布式系统上运行程序数据是需要在机器之间通过网络传输的,这些数据必须被编码成一个个的字节才可以进行传输,这个其实就是我们所谓的数据序列化.数据中心中,最稀缺的资源就是网络带 ...

  5. 使用PowerShell批量解除锁定下载的文件

    使用PowerShell批量解除锁定下载的文件 3.在需要解锁的文件所在的文件夹中空白处,按住Shift然后单击右键,在弹出的右键菜单中,选择“在此处打开PowerShell窗口”, 输入Get-Ch ...

  6. child_process

    child_process const { spawn } = require('child_process'); const ls = spawn('ls', ['-lh', '/usr']); l ...

  7. 什么是APP???APP的开发类型又分哪几种???

    开发者们都知道在高端智能手机系统中有两种应用程序: 一种是基于本地(操作系统)运行的APP —-Native App: 一种是基于高端机的浏览器运行的App —-WebApp因为这些高端智能手机(Ip ...

  8. C#网易云音乐播放器

    效果图: •实现教程: 打开VStudio 2015 #新建一个windows界面工程然后按我的界面来添加控件代码如下 namespace NeteaseMuisc { partial class M ...

  9. day 15

    1.input标签默认内容 Title <input value="默认内容"/> <hr /> <textarea>默认内容</text ...

  10. 创建第一个windows服务

    windows服务应用程序是一种长期运行在操作系统后台的程序,它对于服务器环境特别适合,它没有用户界面,不会产生任何可视输出,任何用户输出都回被写进windows事件日志. 计算机启动时,服务会自动开 ...