D. Gargari and Permutations
题意:k个串,分别是1~n的某种排列,输出k个串的最长公共子序列。
思路:如果像两个串那样dp求LCS复杂度是O(n^k),是不行的。如果先求两个串的LCS,再和下一个串求LCS,直到最后一个串,也是不行的,因为两个串的LCS可能是多解的。我的方法是对每个串,如果串中i在j前面,就建一条边,然后对k个图进行与运算,合成一个图,再对这个图求最长路。
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <memory.h>
#in