状态压缩DP。 先将所有位置离散化,然后在每一个 的 vector 中插入 和 ,当枚举到 时,可以从 转移而来,令当前状态为 ,则 ,其中 表示离散化后某个位置代表的真实位置。 时间复杂度 #include<bits/stdc++.h> #define re //register using namespace std; inline int read(){ re int t=0;re char v=getchar(); while(v<'0')v=getchar(); while(v>='0')t=(t<<3)+(t<<1)+v-48,v=...