基因匹配(bzoj 1264)
Description
Input
Output
Sample Input
1 1 2 2 1 1 2 1 2 2
1 2 2 2 1 1 2 2 1 1
Sample Output
HINT
[数据约束和评分方法]
60%的测试数据中:1<=N <= 1 000
100%的测试数据中:1<=N <= 20 000
/*
考虑LCS如何优化。
因为在做LCS时,只有a[i]==b[j],才会加一,而且这道题相同的只有五个,所以可以提前把位置记下来,用一维数组转移。
即f[i]=max(f[j]+1) a[i]==b[j],用树状数组维护一下最大值。
*/
#include<cstdio>
#include<iostream>
#define N 100010
using namespace std;
int f[N],pos[N][],mx[N],n;
int query(int x){
int ans=;
for(;x>;x-=(x&-x))ans=max(ans,f[x]);
return ans;
}
void change(int x,int v){
for(;x<=n*;x+=(x&-x))f[x]=max(f[x],v);
}
int main(){
scanf("%d",&n);
for(int i=;i<=n*;i++){
int x;scanf("%d",&x);
pos[x][++pos[x][]]=i;
}
int ans=;
for(int i=;i<=n*;i++){
int x;scanf("%d",&x);
for(int j=;j>=;j--){
int k=pos[x][j];
f[k]=max(f[k],query(k-)+);
change(k,f[k]);
ans=max(ans,f[k]);
}
}
printf("%d",ans);
return ;
}
基因匹配(bzoj 1264)的更多相关文章
- 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个位置, 然后从左往右扫第二个序 ...
- bzoj 1264: [AHOI2006]基因匹配Match
1264: [AHOI2006]基因匹配Match Description 基因匹配(match) 卡卡昨天晚上做梦梦见他和可可来到了另外一个星球,这个星球上生物的DNA序列由无数种碱基排列而成(地球 ...
- BZOJ 1264: [AHOI2006]基因匹配Match 树状数组+DP
1264: [AHOI2006]基因匹配Match Description 基因匹配(match) 卡卡昨天晚上做梦梦见他和可可来到了另外一个星球,这个星球上生物的DNA序列由无数种碱基排列而成(地球 ...
- 1264: [AHOI2006]基因匹配Match
1264: [AHOI2006]基因匹配Match Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 982 Solved: 635[Submit][S ...
- 1264: [AHOI2006]基因匹配Match(动态规划神题)
1264: [AHOI2006]基因匹配Match 题目:传送门 简要题意: 给出两个序列.每个序列都由n种不同的数字组成,保证每个序列种每种数字都会出现5次(位置不一定一样),也就是序列长度为5*n ...
- 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][ ...
- [AHOI2006]基因匹配
题目描述 卡卡昨天晚上做梦梦见他和可可来到了另外一个星球,这个星球上生物的DNA序列由无数种碱基排列而成(地球上只有4种),而更奇怪的是,组成DNA序列的每一种碱基在该序列中正好出现5次!这样如果一个 ...
随机推荐
- Leetcode 69. Sqrt(x)
Implement int sqrt(int x). 思路: Binary Search class Solution(object): def mySqrt(self, x): "&quo ...
- git的详细说明文档
http://www.ihref.com/read-16369.html fork 后如何保持同步 http://www.tuicool.com/articles/6vayqen git clone ...
- Codeforces Round #384 (Div. 2) B. Chloe and the sequence(规律题)
传送门 Description Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems ...
- POJ 3278 Catch That Cow(bfs)
传送门 Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 80273 Accepted: 25 ...
- FZU 2105Digits Count(线段树 + 成段更新)
Description Given N integers A={A[0],A[1],...,A[N-1]}. Here we have some operations: Operation 1: AN ...
- JSON资料整理
http://www.cnblogs.com/zxlovenet/p/3566802.html
- nodejs URL解析
说到URL就需要提一下URI,一个网址就是一个URL,是一个具体的符号,说明了要通过什么协议来访问某种资源,URI是一个字符格式规范,URL是URI的一个子集,URL肯定是URI,但URI却不一定是U ...
- Newtonsoft.Json高级用法
http://blog.csdn.net/chengmodelong/article/details/46680143
- 初识pipeline
1.pipeline的产生 从一个现象说起,有一家咖啡吧生意特别好,每天来的客人络绎不绝,客人A来到柜台,客人B紧随其后,客人C排在客人B后面,客人D排在客人C后面,客人E排在客人D后面,一直排到店面 ...
- 顶级域名和二级域名cookie共享删除和修改
原文地址: https://segmentfault.com/a/1190000006932934