hdu 5495 BestCoder Round #58 (div.2) 1002
来源:互联网 发布:新商盟软件下载 编辑:程序博客网 时间:2024/05/29 16:27
题目:点击打开链接
分析:求连个序列的最长公共子序列,因为可以按照给定的序列p来排列a,b序列,所以只要求出a,b可以构成多少个环就可以了,自环一定可以是公共序列一部分,环-1也可以构成公共序列一部分。
#include<cstdio>#include<cstring>using namespace std;const int maxn=100007;int a[maxn],b[maxn],pa[maxn],pb[maxn];bool vis[maxn];int main(){ int T,n,t; // freopen("f.txt","r",stdin); scanf("%d",&T); while(T--){ scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d",&t); pa[t]=i; } for(int i=1;i<=n;i++){ scanf("%d",&b[i]); } memset(vis,0,sizeof(vis)); int ans=n; for(int i=1;i<=n;i++){ if(!vis[i]){ // vis[i]=true; int x=i; int sum=0; while(x){ vis[x]=true; sum++; //printf("%d",x); if(vis[b[pa[x]]])break; x=b[pa[x]]; } if(sum>1)ans--; } } printf("%d\n",ans); }}
0 0
- hdu 5495 BestCoder Round #58 (div.2) 1002
- HDU 5495 LCS(其实就是找环)——BestCoder Round #58(div.1 div.2)
- BestCoder Round #58 (div.2)
- BestCoder Round #58 (div.2)(hdu 5494,hdu5495,hdu5496)
- BestCoder Round #54 (div.2) HDU 5428 The Factor(1002)
- HDU 5671 Matrix (BestCoder Round #81 (div.2) 1002)
- 【HDU】BestCoder Round #11 (Div. 2)
- hdu 5600 BestCoder Round #67 (div.2)
- hdu 5637 BestCoder Round #74 (div.2)
- BestCoder Round #58 (div.2) HDOJ5494 5495 5496 5497题解
- BestCoder Round #52 (div.2)(hdu 5417,hdu 5418)
- BestCoder Round #79 (div.2) hdu 5660 ,hdu 5661
- BestCoder Round #57 (div.2)1002
- BestCoder Round #61 (div.2) 1002
- BestCoder Round #73 (div.2)1002/hdoj5631
- BestCoder Round #11 (Div. 2) Argestes and Sequence (hdu 5057)
- BestCoder Round #54 (div.2) hdu 5428 求质因数
- BestCoder Round #54 (div.2)HDU 5429 Geometric Progression(1003)
- 第四周 项目2-建设“单链表”算法库
- tomcat一闪而过的解决方法!
- ios-技术总结
- ST(稀疏表)算法
- php 成员变量赋值用连接符报错
- hdu 5495 BestCoder Round #58 (div.2) 1002
- App不得不用的控件
- 类似网易新闻分类排序的源码,已经不知道转自哪里,抱歉
- EDA设计:kicad使用及PCB推挤布线,spice电路仿真等
- JVM中的垃圾收集算法
- hdu 5497 Inversion 求逆序对 树状数组
- C++primer学习:顺序容器(3)
- JVM中的垃圾收集器
- cf#323-div2-A. Asphalting Roads-简单模拟