BZOJ1264——[AHOI2006]基因匹配Match
1、题意,求最长公共子序列,每个数字在序列中都出现5次
2、分析:最长公共子序列的标准解法是dp,$O(n^2)$过不了的,然后我们发现判断哪两个位置优化的地方用$5n$就可以搞定了,那么我们用BIT优化一波,就AC了
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
#define M 100010
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;
}
int pos[M][6], cnt[M];
int c[M];
int n, f[M];
inline void change(int x, int k){
for(; x <= n; x += (x & -x)) c[x] = max(c[x], k);
}
inline int get_ans(int x){
int ret = 0;
for(; x > 0; x -= (x & -x)) ret = max(ret, c[x]);
return ret;
}
int main(){
n = read() * 5;
for(int i = 1; i <= n; i ++){
int x = read();
pos[x][++ cnt[x]] = i;
}
int ans = 0;
for(int i = 1; i <= n; i ++){
int x = read();
for(int j = 5; j >= 1; j --){
int k = pos[x][j];
f[k] = max(f[k], get_ans(k - 1) + 1);
change(k, f[k]);
ans = max(ans, f[k]);
}
}
printf("%d\n", ans);
return 0;
}
BZOJ1264——[AHOI2006]基因匹配Match的更多相关文章
- BZOJ1264: [AHOI2006]基因匹配Match
1264: [AHOI2006]基因匹配Match Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 541 Solved: 347[Submit][S ...
- bzoj1264 [AHOI2006]基因匹配Match 树状数组+lcs
1264: [AHOI2006]基因匹配Match Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1255 Solved: 835[Submit][ ...
- BZOJ1264 [AHOI2006]基因匹配Match 【LCS转LIS】
题目链接 BZOJ1264 题解 平凡的\(LCS\)是\(O(n^2)\)的 显然我们要根据题目的性质用一些不平凡的\(LCS\)求法 这就很巧妙了,, 我们考虑\(A\)序列的每个位置可能匹配\( ...
- BZOJ1264 [AHOI2006]基因匹配Match 动态规划 树状数组
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ1264 题意概括 给出两个长度为5*n的序列,每个序列中,有1~n各5个. 求其最长公共子序列长度. ...
- [BZOJ1264][AHOI2006]基因匹配Match(DP + 树状数组)
传送门 有点类似LCS,可以把 a[i] 在 b 串中的位置用一个链式前向星串起来,由于链式前向星是从后往前遍历,所以可以直接搞. 状态转移方程 f[i] = max(f[j]) + 1 ( 1 &l ...
- 【BZOJ1264】[AHOI2006]基因匹配Match DP+树状数组
[BZOJ1264][AHOI2006]基因匹配Match Description 基因匹配(match) 卡卡昨天晚上做梦梦见他和可可来到了另外一个星球,这个星球上生物的DNA序列由无数种碱基排列而 ...
- 1264: [AHOI2006]基因匹配Match
1264: [AHOI2006]基因匹配Match Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 982 Solved: 635[Submit][S ...
- bzoj 1264 [AHOI2006]基因匹配Match(DP+树状数组)
1264: [AHOI2006]基因匹配Match Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 793 Solved: 503[Submit][S ...
- BZOJ 1264: [AHOI2006]基因匹配Match( LCS )
序列最大长度2w * 5 = 10w, O(n²)的LCS会T.. LCS 只有当a[i] == b[j]时, 才能更新答案, 我们可以记录n个数在第一个序列中出现的5个位置, 然后从左往右扫第二个序 ...
随机推荐
- Struts2 OGNL案例
一>>原始类型与包装类型 先定义两个实体类User和Address User package cn.entity; public class User { private String n ...
- 不封装ajax 带url参数调用接口
html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...
- jQuery ui 框架
jQuery ui框架很多,除了官方提供的jquery UI(如果你还不知道什么是jQuery UI,请看下载了jquery ui后如何使用),还有很多第三方提供的ui框架,因官方提供的jquery ...
- Matlab2015基本语句语法04
1. 输入.输出.格式化输出 1) 读入数据:input >>number: num=input('Give me your number: '); >>string: str ...
- poj1986 LCA
Distance Queries Time Limit: 2000MS Memory Limit: 30000K Total Submissions: 11759 Accepted: 4157 ...
- redis-windows执行redis-cli查询
1.无密码时的访问 redis-cli -h redis > redis > keys *1) "myset"2) "mysortset" redi ...
- 使用css3 filter 实现移入背景变色效果
<!doctype html><html lang="en"><head> <meta charset="UTF-8" ...
- 如何修复Ubuntu 14.04 系统设置丢失的问题
其实遇到这个问题的一个最主要的原因是之前执行过卸载ibus输入法的操作,所以为了避免这个问题请不要卸载ibus输入法,大家依然可以安装fcitx输入法使用. 如果已经出现了这个问题,那该怎么解决呢?很 ...
- myeclipse给项目改了名字,但部署tomcat的项目名还是原来的
如标题所示: 在myeclipse中按F2改了项目名称,之前在tomcat中部署的名称是另一个,再次重新部署,永远是上一个的旧名称 解决办法: 项目点右键-properties-左上角搜索框输入web ...
- Unicode, UTF, ASCII, ANSI format differences
Going down your list: "Unicode" isn't an encoding, although unfortunately, a lot of docume ...