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&& ...
随机推荐
- BZOJ 3224 Tyvj 1728 普通平衡树 | Splay 板子+SPlay详细讲解
下面给出Splay的实现方法(复杂度证明什么的知道是 nlogn 就可以啦) 首先对于一颗可爱的二叉查找树,是不能保证最坏nlogn的复杂度(可以想象把一个升序序列插入) (二叉查找树保证左子树元素大 ...
- Windows关机过程分析与快速关机
原文链接:http://blog.csdn.net/flyoxs/article/details/3710367 Windows开机和关机慢,很多时候慢得令人抓狂.特别是做嵌入式开发时(如XPE和Wi ...
- 【BZOJ 2241 打地鼠】
Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 1430 Solved: 908[Submit][Status][Discuss] Descripti ...
- Intellij Idea debug 远程部署的的tomcat项目
web项目部署到tomcat上之后,有时需要打断点单步调试,如果用的是Intellij idea,可以通过如下方法实现: 开启debug端口,启动tomcat 以tomcat7.0.75为例,打开bi ...
- codeforces803D. Magazine Ad
D. Magazine Adtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutput ...
- BZOJ 2457 双端队列(思维
2457: [BeiJing2011]双端队列 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 582 Solved: 253[Submit][Sta ...
- [Usaco2015 dec]Max Flow 树上差分
[Usaco2015 dec]Max Flow Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 353 Solved: 236[Submit][Sta ...
- bzoj Gty的超级妹子树 块状树
Gty的超级妹子树 Time Limit: 7 Sec Memory Limit: 32 MBSubmit: 500 Solved: 122[Submit][Status][Discuss] De ...
- Sync Data to AWS S3 on Windows Box
1. Install AWS CLI first, windows download link https://s3.amazonaws.com/aws-cli/AWSCLI64.msi 2. The ...
- Android 实现对图片 Exif 的修改(Android 自带的方法)
很多时候我们都要对我们的图片信息进行一些处理,比如向图片中写入经纬度,拍摄时间,设备信息,作者等等. 这个时候我们就要对我们的图片Exif进行写入信息的操作,当然,我们想知道图片的Exif信息,也可以 ...