hihoCoder week227 Longest Subsequence
题目链接 https://hihocoder.com/contest/hiho227/problem/1
题目详解 https://hihocoder.com/discuss/question/5587
#include <bits/stdc++.h>
using namespace std;
#define Max(a,b) ((a>b)?a:b)
const int N = 1e6+;
int n,ans; string s[N], S;
int slen,Slen;
int f[N/][], id[]; void init()
{
for(int i=; i<=; i++)
id[i] = Slen;
for(int i=Slen-; i>=; i--) {
for(int j=; j<; j++) {
f[i][j] = id[j];
}
int x = S[i] - 'a';
id[x] = i;
}
/*
for(int i=0; i<Slen; i++) {
for(int j=0; j<3; j++) {
printf("%d%c",f[i][j],j==2?'\n':' ');
}
}
*/
} void solve(int k)
{
int i=, j=;
while(i == && j < Slen) {
if(S[j] != s[k][i])
j++;
else
i++,j++;
}
j--;
while(i < slen && j < Slen) {
int x= s[k][i] - 'a';
j = f[j][x];
if(j >= Slen) break;
i++;
} if(i >= slen) {
//cout<< k <<" "<< slen<<endl;
ans = Max(ans, slen);
}
return ; } int main()
{
freopen("in.txt","r",stdin);
while(~scanf("%d", &n)) {
ans = ;
for(int i=; i<n; i++)
cin >> s[i];
cin >> S;
Slen = S.length();
init();
for(int i=; i<n; i++) {
slen = s[i].length();
if(slen <= ans || slen > Slen)
continue;
solve(i);
}
printf("%d\n", ans);
}
return ;
}
hihoCoder week227 Longest Subsequence的更多相关文章
- D. Longest Subsequence
D. Longest Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces 632D Longest Subsequence 2016-09-28 21:29 37人阅读 评论(0) 收藏
D. Longest Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Educational Codeforces Round 9 D - Longest Subsequence
D - Longest Subsequence 思路:枚举lcm, 每个lcm的答案只能由他的因子获得,类似素数筛搞一下. #include<bits/stdc++.h> #define ...
- CF632D Longest Subsequence
D. Longest Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Educational Codeforces Round 9 D. Longest Subsequence dp
D. Longest Subsequence 题目连接: http://www.codeforces.com/contest/632/problem/D Description You are giv ...
- [徐州网络赛]Longest subsequence
[徐州网络赛]Longest subsequence 可以分成两个部分,前面相同,然后下一个字符比对应位置上的大. 枚举这个位置 用序列自动机进行s字符串的下标转移 注意最后一个字符 #include ...
- codeforces632D. Longest Subsequence (最小公倍数)
You are given array a with n elements and the number m. Consider some subsequence of a and the value ...
- codeforces 632D. Longest Subsequence 筛法
题目链接 记录小于等于m的数出现的次数, 然后从后往前筛, 具体看代码. #include <iostream> #include <vector> #include < ...
- CodeForces 632D Longest Subsequence
暴力. 虽然$a[i]$最大有${10^9}$,但是$m$最大只有${10^6}$,因此可以考虑暴力. 记$cnt[i]$表示数字$i$有$cnt[i]$个,记$p[i]$表示以$i$为倍数的情况下, ...
随机推荐
- 定时调度任务quartz
依赖 <!-- quartz --> <dependency> <groupId>org.quartz-scheduler</groupId> < ...
- .net 常见异常及其翻译
System.Exception//所有异常的基类型 System.ApplicationException//发生非致命应用程序错误时引发的异常 System.SystemException//为S ...
- maven编译不通过:软件包com.sun.org.apache.xml.internal.security.utils.Base64 不存在
问题:代码中使用了sun公司的第三方私有库,导致编译不通过 maven打包异常:软件包com.sun.org.apache.xml.internal.security.utils.Base64 不存 ...
- python二叉树的深度遍历之先序遍历流程图
- Node.js中环境变量process.env详解
Node.js中环境变量process.env详解process | Node.js API 文档http://nodejs.cn/api/process.html官方解释:process 对象是一个 ...
- myeclipse项目导入IDEA
1.import project from external model (不需要删除myeclipse多余文件) https://blog.csdn.net/d276031034/artic ...
- bzoj1180 tree
题目链接 link cut tree 模板题 link cut tree不都是模板题嘛?(雾 #include<algorithm> #include<iostream> #i ...
- Symfony2 学习笔记之系统路由
mfony2 学习笔记之系统路由 漂亮的URL绝对是一个严肃的web应用程序必须做到的,这种方式使index.php?article_id=57这类的丑陋URL被隐藏,由更受欢迎的像 /read/ ...
- 基于jquery 的dateRangePicker 和 My97DatePicker
引入相应的date插件 <script type="text/javascript" src="../plugins/daterangepicker/moment. ...
- linux下的ifconfig命令
ifconfig工具不仅可以被用来简单地获取网络接口配置信息,还可以修改这些配置. 1.命令格式: ifconfig [网络设备] [参数] 2.命令功能: ifconfig 命令用来查看和配置网络设 ...