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$为倍数的情况下, ...
随机推荐
- MyEclipse10中文乱码
1 进入window->preferences general->content types,可以设置Text对应的default encoding值为UTF-8或为空,然后点击updat ...
- html5-css边框全
/*div{ width: 500px; height: 300px; background: rgb(122,30,60); border: 10px solid black ...
- 四则运算 python
2018103004四则运算练习软件项目报告 此作业的要求参见链接的任务三个人任务:https://mooc1-1.chaoxing.com/mycourse/studentstudy?chapt ...
- 20165305 实验二:Java面向对象程序设计
2-1 参考 http://www.cnblogs.com/rocedu/p/6371315.html#SECUNITTEST 参考http://www.cnblogs.com/rocedu/p/67 ...
- Struts2输入校验(XML方式)
本章主要介绍struts2的XML配置方式输入校验.以下将结合一个实例程序进行说明. 代码结构: 关键代码: RegistAction.javapackage com.alfred.regist.ac ...
- Symfony2 学习笔记之控制器
一个controller是你创建的一个PHP函数,它接收HTTP请求(request)并创建和返回一个HTTP回复(Response).回复对象(Response)可以是一个HTML页面,一个XML文 ...
- 使用Fiddler测试WebApi接口
Fiddler是好用的WebApi调试工具之一,它能记录所有客户端和服务器的http和https请求,允许你监视,设置断点,甚至修改输入输出数据,Fiddler 是以代理web服务器的形式工作的,使用 ...
- 安装ES6及HEAD插件
1.下载相应npm包 es6地址:https://www.elastic.co/downloads/elasticsearch head插件地址:https://github.com/mobz/ela ...
- How to click on a point on an HTML5 canvas in Python selenium webdriver
https://stackoverflow.com/questions/29624949/how-to-click-on-a-point-on-an-html5-canvas-in-python-se ...
- torchvision.datasets.ImageFolder数据加载
ImageFolder 一个通用的数据加载器,数据集中的数据以以下方式组织 root/dog/xxx.png root/dog/xxy.png root/dog/xxz.png root/cat/12 ...