f[i][j]表示用a[1]-a[i]与b[1]-b[j]并且用了b[j]构成的LCIS,
优化:决策集合只增不减,记录最优就行,n^3 -> n^2
读入不知道为啥只能cin,快读要炸第四个点
#include<iostream> #include<cstdio> #define ri register int #define u int namespace opt { inline u in() { u x(0),f(1); char s(getchar()); while(s<'0'||s>'9') { if(s=='-') f=-1; s=getchar(); } while(s>='0'&&s<='9') { x=(x<<1)+(x<<3)+s-'0'; s=getchar(); } return x*f; } } using opt::in; #define NN 3005 namespace mainstay { using std::cin; u N,a[NN],b[NN],f[NN][NN]; inline void solve() { cin>>N; for(ri i(1); i<=N; ++i) cin>>a[i]; for(ri i(1); i<=N; ++i) cin>>b[i]; for(ri i(1); i<=N; ++i) { u v(0); for(ri j(1); j<=N; ++j) { if(b[j]<a[i]) v=std::max(v,f[i-1][j]); if(a[i]^b[j]) f[i][j]=f[i-1][j]; else f[i][j]=v+1; } } u ans(0); for(ri i(1); i<=N; ++i) ans=std::max(ans,f[N][i]); printf("%d",ans); } } int main() { //freopen("x.txt","r",stdin); std::ios::sync_with_stdio(false); mainstay::solve(); }