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$为倍数的情况下, ...
随机推荐
- <1>Cocos Creator安装和启动
学习之间需要了解JavaScritp基本语法和面向对象,详情参考https://blog.csdn.net/jadeshu/article/category/7476938 1.下载Cocos Cre ...
- html5-移动端布局模板
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8&qu ...
- html5-新元素新布局模板
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8&qu ...
- java一维数组作业
package zuoYe; import java.util.Scanner; public class MaxSubArray { public static void main(String[] ...
- npm 代理的设置和取消
管理员权限下的控制台输入: 设置代理 npm config set proxy=http://127.0.0.1:8080 npm config set registry=http://registr ...
- BufferReader BufferWriter
Copying information from one file to another with 'BufferReader BufferWriter' public class Demo5 { p ...
- 转:C#判断ContextMenuStrip右键菜单的来源(从哪个控件弹出来的)
转载自:http://hi.baidu.com/cookiemulan/item/82df8ff867dd53cc531c26c7 有时候,为了提高性能和节约资源,我们会为多个控件,指定同一个右键弹出 ...
- TensorFlow 1.2.0新版本完美支持Python3.6,windows在cmd中输入pip install tensorflow就能下载应用最新tensorflow
TensorFlow 1.2.0新版本完美支持Python3.6,windows在cmd中输入pip install tensorflow就能下载应用最新tensorflow 只需在cmd中输入pip ...
- js多个异步请求
一,两个(或多个)js异步并发执行,怎么在两个AJax异步操作之后执行一个新的操作 原题来自 ES6 方法 1.Promise 包装异步ajax操作,2.定义async 函数,3.用await等待pr ...
- docker exec进程是由谁产生的
1.问题: 通过docker exec产生的进程bash(5704)看ppid是docker-containe(5564),但是通过ptrace进程号5564没有关于clone的系统调用,就算ptra ...