C - Lexicographically Maximum Subsequence

You've got string s, consisting of only lowercase English letters. Find its lexicographically maximum subsequence.

We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk(1 ≤ p1 < p2 < ... < pk ≤ |s|) a subsequence of string s = s1s2... s|s|.

String x = x1x2... x|x| is lexicographically larger than string y = y1y2... y|y|, if either |x| > |y| and x1 = y1, x2 = y2, ... , x|y| = y|y|, or exists such number r (r < |x|, r < |y|), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 > yr + 1. Characters in lines are compared like their ASCII codes.

Input

The single line contains a non-empty string s, consisting only of lowercase English letters. The string's length doesn't exceed 105.

Output

Print the lexicographically maximum subsequence of string s.

Example

Input
ababba
Output
bbba
Input
abbcbccacbbcbaaba
Output
cccccbba

Note

Let's look at samples and see what the sought subsequences look like (they are marked with uppercase bold letters).

The first sample: aBaBBA

The second sample: abbCbCCaCbbCBaaBA

这个题目就是要求出子串中字典序最大的.

由于本题有许多方法,那我就讲一讲我自己的好了.

由于我们要尽量挑字典序最大的字符作为开头(首关键字并不是长度!),所以,我们要记录当前字符串的最大字符,然后,如果剩下的字符里面,已经不存在这个最大的字符,那么这个字符就下调,知道存在.

这样一个纯模拟的过程就好了,不过不知道为什么我在比赛中时间用的稍微有点多......

 #include<cstdio>
 #include<cstring>
 #include<algorithm>
 using namespace std;
 ],nxt[],R[];
 ],c;
 int read(){
     ,f=; char ch=getchar();
     '){if (ch=='-') f=-f; ch=getchar();}
     +ch-',ch=getchar();
     return x*f;
 }
 int main(){
     scanf("%s",a),len=strlen(a),c='a';
     memset(las,,sizeof las);
     memset(nxt,,sizeof nxt);
     ; i>=; i--) ) las[a[i]-'a']=i,nxt[i]=i,R[a[i]-'a']=i;
     else nxt[i]=las[a[i]-'a'],las[a[i]-'a']=i;
     ; i<len; i++) if (c<a[i]) c=a[i];
     ; i<len; i++) if (a[i]==c){
         putchar(c); if (nxt[i]!=i) continue;
         );
     }
     ;
 }

[CodeForces - 197C] C - Lexicographically Maximum Subsequence的更多相关文章

  1. Educational Codeforces Round 32 E. Maximum Subsequence

    题目链接 题意:给你两个数n,m,和一个大小为n的数组. 让你在数组找一些数使得这些数的和模m最大. 解法:考虑 dfs但是,数据范围不允许纯暴力,那考虑一下折半搜索,一个从头开始往中间搜,一个从后往 ...

  2. Codeforces 888E Maximum Subsequence

    原题传送门 E. Maximum Subsequence time limit per test 1 second memory limit per test 256 megabytes input ...

  3. Codeforces 888E - Maximum Subsequence(折半枚举(meet-in-the-middle))

    888E - Maximum Subsequence 思路:折半枚举. 代码: #include<bits/stdc++.h> using namespace std; #define l ...

  4. Educational Codeforces Round 32:E. Maximum Subsequence(Meet-in-the-middle)

    题目链接:E. Maximum Subsequence 用了一个Meet-in-the-middle的技巧,还是第一次用到这个技巧,其实这个技巧和二分很像,主要是在dfs中,如果数量减小一半可以节约很 ...

  5. codeforces 880E. Maximum Subsequence(折半搜索+双指针)

    E. Maximum Subsequence time limit per test 1 second memory limit per test 256 megabytes input standa ...

  6. Codeforces Round #648 (Div. 2) E. Maximum Subsequence Value 贪心

    题意:E.Maximum Subsequence Value 题意: 给你n 个元素,你挑选k个元素,那么这个 k 集合的值为 ∑2i,其中,若集合内至少有 max(1,k−2)个数二进制下第 i 位 ...

  7. 1007. Maximum Subsequence Sum (25)

    Given a sequence of K integers { N1, N2, ..., NK }. A continuous subsequence is defined to be { Ni, ...

  8. PAT - 测试 01-复杂度2 Maximum Subsequence Sum (25分)

    1​​, N2N_2N​2​​, ..., NKN_KN​K​​ }. A continuous subsequence is defined to be { NiN_iN​i​​, Ni+1N_{i ...

  9. Maximum Subsequence Sum(接上篇)

    Given a sequence of K integers { N1, N2, ..., NK }. A continuous subsequence is defined to be { Ni, ...

随机推荐

  1. CSS深入

    块元素:div.h1.p等等. 列表的样式: /*使用系统提供的一些样式:例如无序.有序都可以使用circle*/ ul{ list-style-type: circle; } ol{ list-st ...

  2. openlayers空间点查询之GetFeatureInfo

    在map对象上注册点击方法监听, 这里我用的是wms,当然你也可以查询wfs map.events.register('click', map, function (e) {              ...

  3. Spring (一)

    Spring是一个开源框架,是一个基于IOC和AOP来架构多层的JavaEE 架构 默认是单例模式 IOC就是 Inversion of Control public class Girl { pri ...

  4. hibernate事务规范写法

    @Test public void testTx() { SessionFactory sessionFactory = null; Session session = null; Transacti ...

  5. d3选择全部子节点,不知道class和id

    https://github.com/d3/d3-selection/issues/63 selection.selectAll("*")

  6. Linux实际常用命令

    1.删除0字节文件 find -type f -size 0 -exec rm -rf {} \;  2.查看进程 按内存从大到小排列 ps -e -o “%C : %p : %z : %a”|sor ...

  7. ZOJ 4053 Couleur

    4053 思路: 主席树 先分别求前缀和后缀的逆序数 然后要求某一段的逆序数,就可以根据前缀或着后缀根据容斥求出答案, 这样需要枚举这一段中的数,求之前或者之后有多少个比他大或比他小的数, 这个可以通 ...

  8. Tqdm 进度条可视化模块

    2018-12-04 14:34:25 使用python Tqdm进度条库让你的python进度可视化 Tqdm在阿拉伯语表示进步,在西班牙语中表示我非常爱你.是一个快速,可扩展的Python进度条, ...

  9. python中的break\return\pass\continue用法

    continue: def func(): for i in range(1,11): if i % 2 == 0: continue # 作用是当符合上面的if判语句后,就直接跳过之后的语句,也就是 ...

  10. 20165303 预备作业3 Linux安装及学习

    =20165303 预备作业3 Linux安装及学习 安装虚拟机 按照http://www.cnblogs.com/rocedu/p/6012545.html步骤进行逐步操作,安装虚拟机. 遇到的问题 ...