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&& ...
随机推荐
- 你试过不用if写代码吗?
我在教新手编程时,喜欢给他们一些小小的挑战,比如:不使用if语句(或者三元运算符.switch语句等)解决一些编程问题.这样做有什么意义吗?事实上,它可以迫使你从不同的角度寻找解决方法,也许可以找到更 ...
- BZOJ1875: [SDOI2009]HH去散步 图上边矩乘
这道题十分的坑…… 我作为一只连矩乘都不太会的渣渣看到这道题就只能神搜了….. 首先说一下普通的矩乘求方案,就是高出邻接矩阵然后一顿快速幂….. 矩乘一般就是一些秘制递推….. 再说一下这道题,我们可 ...
- Backup and Restore MySQL Database using mysqlhotcopy
mysqlhotcopy is a perl script that comes with MySQL installation. This locks the table, flush the ta ...
- POJ2699:The Maximum Number of Strong Kings(枚举+贪心+最大流)
The Maximum Number of Strong Kings Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2488 ...
- 数据仓库3级范式(3NF)基础
一.引言 最近在整理理大数据模式下的数据仓库数据模型,资料来自互联网和读过的数据仓库理论和实践相关. 二.3NF (1)1NF-无重复的列 数据库表的每一列都是不可分割的基本数据项,同一列中不能有多个 ...
- 关于applePay详细讲解
https://www.cnblogs.com/diweinan/p/6225501.html
- nginx重要配置项简要说明
1.重要配置项 以下是一个完整的nginx配置信息. #================================以下是全局配置项 #指定运行nginx的用户和用户组,默认情况下该选项关闭(关闭 ...
- Nginx的主要配置参数说明
#定义Nginx运行的用户和用户组user www www; #nginx进程数,建议设置为等于CPU总核心数.worker_processes 8; #全局错误日志定义类型,[ debug | in ...
- 让VC6.0编译出来的程序支持XP样式或XP风格
(1)VC6.0编译出来的win32程序不支持winxp样式的原因:微软WINXP系统更新了Comctl32.dll(ver 6.0)这个“XP风格”的控件.为了保留传统的Windows界面风格,特地 ...
- [Leetcode Week2]Sort Colors
Sort Colors题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/sort-colors/description/ Description Give ...