CF1534F2
发现这是一个 4 4 4 联通问题。我们先考虑建图。
我们需要每一个序列都满足条件,那么我们可以选取最低的点然后考虑其被左右两边影响的区间,也就是左右两边任意掉落一个沙子即可将其掉落。
这个可以使用 d f s dfs dfs 解决。然后我们就得到 n n n 个满足条件的区间。
我们将题目变成了给定 n n n 个区间,选择最少的点使得每一个区间至少有一个点。我们按照左端点为第一关键字,右端点为第二关键字排序。尽量选右边的点即可。
#include <bits/stdc++.h>
using namespace std;
//#define Fread
//#define Getmod
#ifdef Fread
char buf[1 << 21], *iS, *iT;
#define gc() (iS == iT ? (iT = (iS = buf) + fread (buf, 1, 1 << 21, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
#define getchar gc
#endif // Fread
template <typename T>
void r1(T &x) {
x = 0;
char c(getchar());
int f(1);
for(; c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;
for(; '0' <= c && c <= '9';c = getchar()) x = (x * 10) + (c ^ 48);
x *= f;
}
#ifdef Getmod
const int mod = 1e9 + 7;
template <int mod>
struct typemod <