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. HDU 5442 Favorite Donut(暴力 or 后缀数组 or 最大表示法)

    http://acm.hdu.edu.cn/showproblem.php?pid=5442 题意:给出一串字符串,它是循环的,现在要选定一个起点,使得该字符串字典序最大(顺时针和逆时针均可),如果有 ...

  2. R工具包一网打尽

    这里有很多非常不错的R包和工具. 该想法来自于awesome-machine-learning. 这里是包的导航清单,看起来更方便 >>>导航清单 通过这些翻译了解这些工具包,以后干 ...

  3. python 获取进程数据

    from multiprocessing import Process, Manager def func(dt, lt): ): key = 'arg' + str(i) dt[key] = i * ...

  4. jdbcTemplate 后台接口中的分页

    Springboot+jdbcTemplate  对查询结果列表做分页, 之前开发的小项目,数据逐渐增多,每次返回所有的查询结果,耗费性能和时间 想到做分页. 于是从简单的分页做起. jdbcTemp ...

  5. Python安装第三方库的安装技巧

    电脑:Windows10 64位. Python IDE 软件:JetBrains PyCharm Community Edition 2018.1.3 x64 Python version : Py ...

  6. 设置本地虚拟域名windows+apache

    C:\WINDOWS\system32\drivers\etc\hosts 在这个文件中 最下面添加. 127.0.0.1   localhost.com 127.0.0.1   cho.com 12 ...

  7. java 虹软ArcFace 2.0,java SDK使用-进行人脸检测

    虹软产品地址:http://ai.arcsoft.com.cn/product/arcface.html虹软ArcFace功能简介 人脸检测人脸跟踪人脸属性检测(性别.年龄)人脸三维角度检测人脸对比 ...

  8. 录音 voice record

    参考 : http://air.ghost.io/recording-to-an-audio-file-using-html5-and-js/ (html5 基础) https://github.co ...

  9. VNPY回测流程

    又是好久没更新了,2月这一个月,工作上也忙,正好也是过年.加上前一段时间,一直在爬取某眼查的数据. 对VNPY的使用时间就减少了,不过最近还是完成了vnpy回测结构的思维导图.如下: 值得注意的是,v ...

  10. spring cloud: Hystrix(六):feign的注解@FeignClient:fallbackFactory(类似于断容器)与fallback方法

    fallbackFactory(类似于断容器)与fallback方法 feign的注解@FeignClient:fallbackFactory与fallback方法不能同时使用,这个两个方法其实都类似 ...