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. 使用openlayers 3 在线加载天地图及GeoServer发布的地图

    使用openlayers3来加载天地图卫星图和标注图层,GeoServer发布地图,一并用openlayers测试加载出来,顺便实现了7种地图控件.下面直接贴代码: <!DOCTYPE html ...

  2. RN返回navigation方法

    RN官方指定的路由管理是navigation  通过打印我们可以得到navgation的相关属性 1:dispatch ,Redux的事件发起 2:goback()返回 3:navigate(rout ...

  3. mysql 和 sqlserver中备份一张表的区别

    sqlserver中备份一张表 SELECT * into qa_buglist_bak FROM qa_buglist 不管表的数据有多大,速度很快: mysql中上述语句就无效了,须得新建一张表, ...

  4. springBoot集成Redis遇到的坑(择库)源码分析为什么择库失败

    提示: springboot提供了一套链接redis的api,也就是个jar包,用到的连接类叫做LettuceConnectionConfiguration,所以我们引入pom时是这样的 <de ...

  5. zabbix自定义监控方式

  6. python中的进程和线程

    什么是进程(process)? 程序并不能单独运行,只有将程序装载到内存中,系统为它分配资源才能运行,而这种执行的程序就称之为进程.程序和进程的区别就在于:程序是指令的集合,它是进程运行的静态描述文本 ...

  7. python爬虫学习(三):使用re库爬取"淘宝商品",并把结果写进txt文件

    第二个例子是使用requests库+re库爬取淘宝搜索商品页面的商品信息 (1)分析网页源码 打开淘宝,输入关键字“python”,然后搜索,显示如下搜索结果 从url连接中可以得到搜索商品的关键字是 ...

  8. 通过wifi 连接 adb 到 手机

    网上很多文章都需要先用 usb 线连接先做一下设置,然后才能通过下面的方法连接 julian@julian-ThinkPad-T450:~/tools/android_sdk/platform-too ...

  9. Jedis与Lua脚本结合

    使用Lua脚本的好处    1.减少网络开销:可以将多个请求通过脚本的形式一次发送,减少网络时延和请求次数. 2.原子性的操作:Redis会将整个脚本作为一个整体执行,中间不会被其他命令插入.因此在编 ...

  10. 最大似然估计实例 | Fitting a Model by Maximum Likelihood (MLE)

    参考:Fitting a Model by Maximum Likelihood 最大似然估计是用于估计模型参数的,首先我们必须选定一个模型,然后比对有给定的数据集,然后构建一个联合概率函数,因为给定 ...