博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
codeforces Gargari and Permutations(DAG+BFS)
阅读量:7003 次
发布时间:2019-06-27

本文共 774 字,大约阅读时间需要 2 分钟。

1 /* 2      题意:求出多个全排列的lcs! 3      思路:因为是全排列,所以每一行的每一个数字都不会重复,所以如果有每一个全排列的数字 i 都在数字 j的前面,那么i, j建立一条有向边! 4       最后用bfs遍历整个图,求出源点到每一个点的距离,其中最大的距离就是最长的公共子序列的长度! 5 */ 6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #define N 100513 14 using namespace std;15 vector
g[N];16 queue
q;17 int pos[6][N];18 int d[N];19 int vis[N];20 int n, k;21 int ans;22 23 bool judge(int a, int b){ //保证数字a 在数字 b的前边24 for(int i=1; i<=k; ++i)25 if(pos[i][a] > pos[i][b])26 return false;27 return true;28 }29 30 void bfs(int x){31 q.push(x);32 ans=0;33 vis[0]=1;34 while(!q.empty()){35 int u=q.front();36 q.pop(); 37 vis[u]=0;38 ans=max(ans, d[u]);39 int len=g[u].size();40 for(int i=0; i

 

转载地址:http://mwytl.baihongyu.com/

你可能感兴趣的文章