经典问题:嵌套矩形问题
记忆化搜索复杂度和搜索树的边的数目有关(每条边只会使用一次),最坏情况下边数目为n*(n - 1)/2故算法复杂度为O(n^2)
#include<bits/stdc++.h>
#define debug(x) cout<<#x<<" is "<<x<<endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define DBG 0
const int N = 1000 + 5;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LLINF = (1LL<<60);
using namespace std;
const int mod = 998244353;
ll fast_pow(ll a,ll b){
ll ans = 1;
while(b){
if(b&1)ans = (ans * a)%mod;
a = (a * a)%mod;
b>>=1;
}
return (ans%mod);
}
typedef pair<int,int> pii;
int G[N][N],in[N],out[N];
int n;
int ans[N];
struct rect{
int x,y;
};
vector<rect> v;
int dfs(int i){
if(ans[i] != -1)return ans[i];
if(out[i] == 0)return ans[i] =