codeforces176D——Hyper String
来源:互联网 发布:淘宝台湾入台证办理 编辑:程序博客网 时间:2024/05/17 05:49
1、题意:给一些字符串,总长度小于
2、分析:首先既然最长公共子序列,考虑dp,
#include <map>#include <set>#include <cmath>#include <queue>#include <vector>#include <bitset>#include <string>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>using namespace std;#define M 1000010#define LL long long#define MOD 1000000007#define inf 2147483647#define llinf 4000000000000000000ll#define For(i, x, y) for(int i = (x); i < (y); i ++)#define rep(i, x, y) for(int i = (x); i <= (y); i ++)#define drep(i, x, y) for(int i = (x); i >= (y); i --)inline int read(){ char ch=getchar();int x=0,f=1; while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while('0'<=ch&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}inline LL llread(){ char ch=getchar();LL x=0,f=1; while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while('0'<=ch&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}//pair<int , int> Next[2010][26];int nxt[M][26];string str[2010];int id[2010], sum[2010];int head[26];pair<int , int> f[2010][2010];inline pair<int , int> calculate(pair<int , int> now, int latin){ bool flag = false; if(now.first == 1 && now.first == 1) flag = true; if(now.first == inf || now.second == inf) return make_pair(inf, inf); pair<int , int> ret = make_pair(now.first, 0); if(now.second != str[id[now.first]].size()){ //cout << "fuck" << endl; int t = nxt[sum[id[now.first] - 1] + now.second + 1][latin]; if(t != -1) ret.second = t; else ret = Next[now.first + 1][latin]; } else ret = Next[now.first + 1][latin]; if(ret.first == -1 || ret.second == -1) ret = make_pair(inf, inf); return ret;}inline void solve(){ string st; cin >> st; int len = st.size(); For(i, 0, 2010) For(j, 0, 2010) f[i][j] = make_pair(inf, inf); f[0][0] = make_pair(0, 0); int ans = 0; rep(i, 1, len){ rep(j, 0, i){ if(j) f[i][j] = min(f[i - 1][j], calculate(f[i - 1][j - 1], st[i - 1] - 'a')); else f[i][j] = f[i - 1][j]; if(f[i][j] != f[2005][2005]) ans = max(ans, j); /*if(f[i][j] != f[2005][2005]){ if(j == 2){ printf("%d %d %d %d\n", i, j, f[i - 1][j - 1].first, f[i - 1][j - 1].second); } }*/ } } cout << ans << endl; return; }int main(){ //freopen("0input.in", "r", stdin); int n = read(); rep(i, 1, n) cin >> str[i]; int m = read(); rep(i, 1, m) id[i] = read(); memset(nxt, -1, sizeof(nxt)); For(i, 0, 2010) For(j, 0, 26) Next[i][j] = make_pair(-1, -1); rep(i, 1, n){ sum[i] = sum[i - 1] + str[i].size(); memset(head, 0, sizeof(head)); For(j, 0, str[i].size()){ //if(head[str[i][j] - 'a'] != -1){ if(!head[str[i][j] - 'a']) head[str[i][j] - 'a'] = sum[i - 1]; rep(kt, head[str[i][j] - 'a'] + 1, sum[i - 1] + j + 1){ nxt[kt][str[i][j] - 'a'] = j + 1; } head[str[i][j] - 'a'] = sum[i - 1] + j + 1; //} } } drep(i, m, 1){ rep(j, 0, 25){ if(nxt[sum[id[i] - 1] + 1][j] != -1) Next[i][j] = make_pair(i, nxt[sum[id[i] - 1] + 1][j]); else Next[i][j] = Next[i + 1][j]; } } //cout << Next[1][0].first << endl << Next[2][0].first; solve(); return 0;}
0 0
- codeforces176D——Hyper String
- 【Codeforces176D】Hyper String
- VMware与Hyper—V使用感受
- Hyper
- Hyper-V组件架构(2)——虚拟网络
- Hyper-V的备份方式——snapshot虚拟机快照
- Hyper-V 组件架构(1)—总体架构
- 超融合架构 — Hyper Converged Infrastructure 小记
- UVA11488——Hyper Prefix Sets(字典树,最长前缀)
- Http协议——Hyper Text Transfer Protocol(超文本传输协议)
- Hyper-V
- 在Hyper
- Hyper Thread
- C/C++——*string++、*++string、++*string的区别
- String——string-to-integer-atoi
- MAC上搭建Windows Phone 8 开发环境——VMware Fusion下Win8 “无法安装Hyper-V, 某个虚拟机监控程序正在运行”问题解决的办法
- WIN7上搭建Windows Phone 8 开发环境——VMware Workstation下Win8 “无法安装Hyper-V, 某个虚拟机监控程序正在运行”问题解决的办法
- MAC上搭建Windows Phone 8 开发环境——VMware Fusion下Win8 “无法安装Hyper-V, 某个虚拟机监控程序正在运行”问题解决的办法
- 博客迁移->>>>>>博客园-Jackson0714
- ReactiveCocoa核心元素与信号流
- window 异步脚本 同时启动两个可执行文件
- angular-toaster 入坑记
- List用法
- codeforces176D——Hyper String
- 预习shell编程
- CSS 8.5 图像透明度
- Linux系统编程——I/O多路复用select、poll、epoll的区别使用
- test legendyang
- java设计模式之单例模式(一)
- 【面试题】海量数据面试题分析
- 创建多线程的几种方式
- SQLITE3写简易通信录