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$为倍数的情况下, ...
随机推荐
- Object-C-自定义类型归档
对自定义类型的对象进行本地化保存,那么该类型必须实现NSCoding协议! NSCoding 协议中只有两个方法,都是require的方法,一个是把本身的类型进行编码,一个是解码成类对象,返回一个对象 ...
- Python -- Pandas介绍及简单实用【转】
转http://www.datadependence.com/2016/05/scientific-python-pandas/ 一. Pandas简介 1.Python Data Analysis ...
- Python - 3. Input and Output
from:http://interactivepython.org/courselib/static/pythonds/Introduction/InputandOutput.html Input a ...
- HTML标签-----article、aside、figure、nav和section
article <article> 标签定义独立的内容 <!DOCTYPE html> <html> <head> <meta cha ...
- PCH 文件 和 ProjectName-Bridging-Header 配置
1.简介 PCH文件是Xcode编程中全局引用共享的文件.可以在这里引入头文件或者宏定义来方便程序中多个文件访问. 2.PCH文件创建 打开工程 New File… -> iOS Other - ...
- tensorflow学习3---mnist
import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data '''数据下载''' mnist= ...
- bzoj4445 小凸想跑步
题目链接 半平面交,注意直线方向!!! 对于凸包上任意一条边$LINE(p_i,p_{i+1})$都有$S_{\Delta{p_i} {p_{i + 1}}p} < S_{\Delta{p_0} ...
- web前端学习路线(含20个真实web开发项目集合)
目前web前端工程师日均岗位缺口已经超过50000,随着互联网+的深入发展,html5作为前端展示技术,市场人才需求量将呈直线上涨. Web前端工程师的岗位职责是利用HTML.CSS.Java.DOM ...
- 怎样从外网访问内网Lighttpd?
本地安装了一个Lighttpd,只能在局域网内访问,怎样从外网也能访问到本地的Lighttpd呢?本文将介绍具体的实现步骤. 准备工作 安装并启动Lighttpd 默认安装的Lighttpd端口是80 ...
- P2P原理及UDP穿透简单说明(转)
源: P2P原理及UDP穿透简单说明