 /**//*
给出如图的电路布线,求最大的一块,其中里面的线两两相交
n<=10^6
看解题报告的:
http://itbhu.ac.in/codefest/problem.php?pid=102
它说这是一个Permutation Graph
先将上面那排的数字映射为1,2, ,n,然后下面那排再映射一下
其中的最大图就是最长下降子序列了 -------------------------------OMG
O(nlogn)
*/
#include<iostream>
#include<cstring>
#include<map>
#include<algorithm>
#include<stack>
#include<queue>
#include<cmath>
#include<string>
#include<cstdlib>
#include<vector>
#include<cstdio>
#include<set>
#include<list>
#include<numeric>
#include<cassert>
#include<ctime>
#include<bitset>

using namespace std;

const int MAXN = 1000010;

int a[MAXN];

 bool cmp(const int &a , const int &b) {
return a > b;
}

int main()
  {
#ifndef ONLINE_JUDGE
freopen("in","r",stdin);
#endif
ios::sync_with_stdio(false);//取消跟stdin的同步 然后cin,cout就不要跟scanf,printf混用了
 for (int n ; cin>>n ; ) {
 for (int i = 1, x ; i <= n ; i++) {
cin>>x;
a[x] = i;//
}
vector<int> rec;
 for (int i = 1, x; i <= n ; i ++) {
cin>>x;
x = a[x];//
int pos = upper_bound(rec.begin(), rec.end(), x, cmp) - rec.begin();
 if(pos == rec.size()) {
rec.push_back(0);
}
rec[pos] = x;
}
cout<<rec.size()<<endl;
}
return 0;
}
|
|
常用链接
随笔分类
Links
搜索
最新评论

|
|