bzoj 1264: [AHOI2006]基因匹配Match 树状数组
来源:互联网 发布:工行td交易软件 编辑:程序博客网 时间:2024/05/21 17:12
题意
给出两个长度为5*n的序列,每个序列中[1,n]每个元素恰好出现5次。问其最长公共子序列。
n<=20000
分析
枚举第一个序列,设f[i]表示到当前时刻,第二个序列中最后一位为第i位的最长公共子序列的长度是多少。然后用树状数组来加速转移即可。
代码
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>using namespace std;const int N=100005;int n,pos[N/5][6],c[N],tot[N/5];void ins(int x,int y){ while (x<=n) c[x]=max(c[x],y),x+=x&(-x);}int query(int x){ int ans=0; while (x) ans=max(ans,c[x]),x-=x&(-x); return ans;}int main(){ scanf("%d",&n);n*=5; for (int i=1;i<=n;i++) { int x; scanf("%d",&x); tot[x]++;pos[x][tot[x]]=i; } for (int i=1;i<=n;i++) { int x; scanf("%d",&x); for (int j=5;j>=1;j--) ins(pos[x][j],query(pos[x][j]-1)+1); } printf("%d",query(n)); return 0;}
阅读全文
0 0
- BZOJ 1264 AHOI2006 基因匹配Match 动态规划+树状数组
- bzoj 1264 [AHOI2006]基因匹配Match(DP+树状数组)
- BZOJ 1264: [AHOI2006]基因匹配Match 树状数组,DP
- bzoj 1264: [AHOI2006]基因匹配Match (DP+树状数组)
- bzoj 1264: [AHOI2006]基因匹配Match 树状数组
- bzoj 1264: [AHOI2006]基因匹配Match(树状数组)
- 1264: [AHOI2006]基因匹配Match DP+树状数组
- bzoj 1264: [AHOI2006]基因匹配Match
- bzoj 1264: [AHOI2006]基因匹配Match
- 【BZOJ1264】[AHOI2006]基因匹配Match【DP】【LCS】【树状数组】
- bzoj1264 [AHOI2006]基因匹配Match (树状数组优化DP)
- 1264: [AHOI2006]基因匹配Match
- BZOJ 1264 Match 基因匹配 (dp 树状数组优化)
- BZOJ 1264: [AHOI2006]基因匹配Match|动态规划
- BZOJ 1264 [AHOI2006]基因匹配Match DP+BIT
- dp+树状数组 bzoj1264 AHOI2006基因匹配
- [bzoj1264][AHOI2006]基因匹配Match 树状数组优化dp
- bzoj1264: [AHOI2006]基因匹配Match
- 开发分层各层作用
- 背包问题总结:双线程背包 RQNOJ329,202
- Oracle异常汇总
- 随机森林
- 炮 HYSBZ
- bzoj 1264: [AHOI2006]基因匹配Match 树状数组
- 相机 镜头原理及其选型
- Leetcode OJ 23 Merge k Sorted Lists [Hard]
- 2017/8/31
- mysql无密码登录
- tf入门
- python数据结构之字符串
- flask-用户认证(上)
- 【Shell指令】Linux nohup命令详解