Don't Be a Subsequence
问题 F: Don't Be a Subsequence
时间限制: 1 Sec 内存限制: 128 MB
提交: 33 解决: 2
[提交] [状态] [讨论版] [命题人:]
题目描述
You are given a string A consisting of lowercase English letters. Find the shortest string among the strings consisting of lowercase English letters that are not subsequences of A. If there are more than one such string, find the lexicographically smallest one among them.
Constraints
1≤|A|≤2×105
A consists of lowercase English letters.
输入
A
输出
样例输入
atcoderregularcontest
样例输出
b
提示
The string atcoderregularcontest contains a as a subsequence, but not b.
分析:这题。。勉强算个图论吧
- 首先,动态规划确定最短子串的长度,dp[i]为[i….)这一段中最短的非子序列长度。
- 则dp[i]=min(dp[i],dp[next[i][j]+1]+1)
- 再反着走回来枚举26个字母,取字典序最小的字母输出。
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#define range(i,a,b) for(auto i=a;i<=b;++i)
#define LL long long
#define itrange(i,a,b) for(auto i=a;i!=b;++i)
#define rerange(i,a,b) for(auto i=a;i>=b;--i)
#define fill(arr,tmp) memset(arr,tmp,sizeof(arr))
using namespace std;
int dp[int(2e5+5)],alpha[30],NEXT[int(2e5+5)][30],len;
string word;
void init(){
cin>>word;
len=int(word.size());
range(i,0,25)alpha[i]=len;
rerange(i,len-1,0){
alpha[word[i]-'a']=i;
range(j,0,25)NEXT[i][j]=alpha[j];
dp[i]=int(1e9+7);
}
dp[len]=1;
}
void solve(){
rerange(i,len-1,0)
range(j,0,25)dp[i]=min(dp[i],dp[NEXT[i][j]+1]+1);
int pos=0;
rerange(i,dp[0],0)range(j,0,25)if(dp[pos]==dp[NEXT[pos][j]+1]+1){
putchar('a'+j);
pos=NEXT[pos][j]+1;
break;
}
}
int main() {
init();
solve();
return 0;
}
Don't Be a Subsequence的更多相关文章
- [LeetCode] Arithmetic Slices II - Subsequence 算数切片之二 - 子序列
A sequence of numbers is called arithmetic if it consists of at least three elements and if the diff ...
- [LeetCode] Is Subsequence 是子序列
Given a string s and a string t, check if s is subsequence of t. You may assume that there is only l ...
- [LeetCode] Wiggle Subsequence 摆动子序列
A sequence of numbers is called a wiggle sequence if the differences between successive numbers stri ...
- [LeetCode] Increasing Triplet Subsequence 递增的三元子序列
Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the ar ...
- [LeetCode] Longest Increasing Subsequence 最长递增子序列
Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...
- 动态规划求最长公共子序列(Longest Common Subsequence, LCS)
1. 问题描述 子串应该比较好理解,至于什么是子序列,这里给出一个例子:有两个母串 cnblogs belong 比如序列bo, bg, lg在母串cnblogs与belong中都出现过并且出现顺序与 ...
- 【LeetCode】Increasing Triplet Subsequence(334)
1. Description Given an unsorted array return whether an increasing subsequence of length 3 exists o ...
- CF724D. Dense Subsequence[贪心 字典序!]
D. Dense Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
- [tem]Longest Increasing Subsequence(LIS)
Longest Increasing Subsequence(LIS) 一个美丽的名字 非常经典的线性结构dp [朴素]:O(n^2) d(i)=max{0,d(j) :j<i&& ...
随机推荐
- 洛谷P4589 [TJOI2018]智力竞赛 【floyd + 二分 + KM】
题目链接 洛谷P4589 题意可能不清,就是给出一个带权有向图,选出\(n + 1\)条链,问能否全部点覆盖,如果不能,问不能覆盖的点权最小值最大是多少 题解 如果要问全部覆盖,就是经典的可重点的DA ...
- POJ2253:Frogger(改造Dijkstra)
Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 64864 Accepted: 20127 题目链接:ht ...
- POJ 1050 To the Max 二维最大子段和
To the MaxTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 52281 Accepted: 27633Description ...
- JSON.parse() 和 JSON.stringify()使用
1.parse()是用于从一个字符串中解析出json对象 定义一个字符串:var str = '{"name":"superman","age&quo ...
- JS知识总结
1.javascript继承机制 原型继承,访问对象属性时,如果对象内部有就返回,找不到就会从对象原型指向的对象原型中查找,一层一层的查找,直到最顶层的对象原型还找不到,就返回undefined. 2 ...
- NodeJS概述
NodeJS中文API 一.概述 Node.js 是一种建立在Google Chrome’s v8 engine上的 non-blocking (非阻塞), event-driven (基于事件的) ...
- [POJ2954&POJ1265]皮克定理的应用两例
皮克定理: 在一个多边形中.用I表示多边形内部的点数,E来表示多边形边上的点数,S表示多边形的面积. 满足:S:=I+E/2-1; 解决这一类题可能运用到的: 求E,一条边(x1,y1,x2,y2)上 ...
- 【CodeForces】841C. Leha and Function(Codeforces Round #429 (Div. 2))
[题意]定义函数F(n,k)为1~n的集合中选择k个数字,其中最小数字的期望. 给定两个数字集A,B,A中任意数字>=B中任意数字,要求重组A使得对于i=1~n,sigma(F(Ai,Bi))最 ...
- Linux make命令详解
在linux环境下的工作,免不了需要经常编译C/C++源代码,所以make命令是我们经常都会用到的.当然make工具不一定针对C代码,它也可以维护其他各种代码,详见:man make 在列举其详 ...
- 基于vlc sdk的二次开发--环境搭建、编译
前言 关于 搭建.编译VLC,不同的平台有不同的方法,可以参考wiki. 其中在windows下编译VLC有两种方式,MSYS+MinGW和CygWin.通过测试,最后决定采用MSYS+MinGW搭建 ...