題目鏈接
題目解法
詢問長度爲 的序列 可以查詢 是否在答案中排在 的前面。
由此,用 std :: stable_sort 或是歸併排序對 到 進行排序即可。
時間複雜度 。
#include "lcs.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 5;
void find_permutation(int n, int *res) {
for (int i = 0; i <= n - 1; i++) res[i] = i + 1;
stable_sort(res, res + n, [&] (int x, int y) {
int tmp[2] = {x, y};
return get_lcs(2, tmp) == 2;
});
}