1 条题解
-
-1huangguangrun LV 5 @ 2024-8-14 20:42:33
#include <iostream> #include <vector> #include <algorithm>
using namespace std;
const int MOD = 1000000007;
bool cmp(const pair<int, int>& p1, const pair<int, int>& p2) { return p1.second > p2.second; }
void backtrack(vector<pair<int, int>>& points, int index, vector<pair<int, int>>& subset, int& count) { if (!subset.empty()) { bool is = true; for (int j = 2; j < subset.size(); ++j) { int xj = subset[j].first; int xj_1 = subset[j - 1].first; int xj_2 = subset[j - 2].first; if (!((xj_2 < xj && xj < xj_1) || (xj_1 < xj && xj < xj_2))) { is = false; break; } } if (is) { count = (count + 1) % MOD; } } for (int i = index; i < points.size(); ++i) { subset.push_back(points[i]); backtrack(points, i + 1, subset, count); subset.pop_back(); } }
int main() { int n; cin >> n; vector<pair<int, int>> points(n); for (int i = 0; i < n; ++i) { cin >> points[i].first >> points[i].second; } sort(points.begin(), points.end(), cmp); vector<pair<int, int>> subset; int count = 0; backtrack(points, 0, subset, count); cout << count; return 0; }
我哪错了?
- 1
信息
- ID
- 2872
- 时间
- 2000ms
- 内存
- 256MiB
- 难度
- 9
- 标签
- 递交数
- 76
- 已通过
- 7
- 上传者