bzoj1264(lcs->lis)

这题跟xdoj的一道挺像。。。做法一模一样。。

https://blog.csdn.net/qkoqhh/article/details/78143809

不过每个数字可以出现5次。。那么就考虑将每个数字当成5个位置的数来处理,然后跑一遍lis即可。。

不过要注意5个位置要倒着过来,这和01背包的处理方式一样。。

/**
 *          ┏┓    ┏┓
 *          ┏┛┗━━━━━━━┛┗━━━┓
 *          ┃       ┃  
 *          ┃   ━    ┃
 *          ┃ >   < ┃
 *          ┃       ┃
 *          ┃... ⌒ ...  ┃
 *          ┃              ┃
 *          ┗━┓          ┏━┛
 *          ┃          ┃ Code is far away from bug with the animal protecting          
 *          ┃          ┃   神兽保佑,代码无bug
 *          ┃          ┃           
 *          ┃          ┃        
 *          ┃          ┃
 *          ┃          ┃           
 *          ┃          ┗━━━┓
 *          ┃              ┣┓
 *          ┃              ┏┛
 *          ┗┓┓┏━━━━━━━━┳┓┏┛
 *           ┃┫┫       ┃┫┫
 *           ┗┻┛       ┗┻┛
 */
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<bitset>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define eps 1e-8
#define succ(x) (1LL<<(x))
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define mid (x+y>>1)
#define NM 100005
#define nm 1000005
#define N 1000005
#define M(x,y) x=max(x,y)
const double pi=acos(-1);
const int inf=10007;
using namespace std;
ll read(){
    ll x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return f*x;
}
 


int n,b[NM],v[NM],d[NM],len;
vector<int>a[NM];


int main(){
    n=read()*5;
    inc(i,1,n)a[read()].push_back(i);
    inc(i,1,n)b[i]=read();
    d[len=1]=a[b[1]][0];
    inc(i,2,n)dec(j,4,0)if(d[len]<a[b[i]][j])d[++len]=a[b[i]][j];else d[lower_bound(d,d+1+len,a[b[i]][j])-d]=a[b[i]][j];
    //inc(i,1,len)printf("%d ",d[i]);putchar('\n');
    return 0*printf("%d\n",len);
}

猜你喜欢

转载自blog.csdn.net/qkoqhh/article/details/81449658
今日推荐