私は解決策をに従っている問題のほとんどを見て(\ \ mathcal {DP} \ ) それを行うこと。
しかし、本ガチョウ基本的に弱い\(\ mathscr {DP} \ ) 親指。
だから、あなたの場合、\(\ mathcal {YY} \ ) 別の清チーアプローチ。
我々は2点の条件を満たしているたびに\(X(i、j)は 、Y(i、j)は(X_I <Y_I、X - jが<y_j)\) エッジを構築します
\(X \)ポイント\(Y \) 。
明らかにすべてのポイントを添加した後、少なくとも1つのゼロ度点の存在。
限り我々トポロジカル整列、各レコードの最長の現在の値、そして最後として\(DFS \)出力プログラムだけで罰金。
それは注目に値する:この質問は、比較的大きなスペースを必要とします。我々は、隣接行列を使用する必要がありますので。
隣接リストは、隣接行列スペースなので\(2 \) 、二重\(N \)(1つのドットが2回記録され、\(頭が\)である(N \)\)
第二に隣接行列タイプを使用する\(BOOLを\)そうでなければ、まだ、\(\ mathcal {MLE} \ )
以下は、\(\ mathcal {\カラー{緑} {AC}} \) :コード
#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
using namespace std;
#define ri register int
bool mat[5002][5002];
int len[5002], pre[5002], id[5002];
int wf[5002], hf[5002], in[5002];
int n, w, h, cnt, cnte, ans, fin;
inline void topo()
{
queue<int> bf;
for (ri i = 1; i <= cnt; ++i)
if (in[i] == 0) bf.push(i), len[i] = 1;
while (!bf.empty())
{
int now = bf.front();
bf.pop();
if (ans < len[now])
{
ans = len[now];
fin = now;
}
for (ri i = 1; i <= cnt; ++i)
{
if (i == now || !mat[now][i]) continue;
--in[i];
if (len[i] < len[now] + 1)
len[i] = len[now] + 1, pre[i] = now;
if (in[i] == 0)
bf.push(i);
}
}
}
void dfs(int p)
{
if (p == 0) return;
if (pre[p]) dfs(pre[p]);
printf("%d ", id[p]);
}
int main()
{
scanf("%d%d%d", &n, &w, &h);
for (ri i = 1; i <= n; ++i)
{
int x, y;
scanf("%d%d", &x, &y);
if (x <= w || y <= h) continue;
wf[++cnt] = x, hf[cnt] = y;
id[cnt] = i;
}
if (cnt == 0)
{
printf("0\n");
return 0;
}
for (ri i = 1; i < cnt; ++i)
for (ri j = i + 1; j <= cnt; ++j)
{
if (wf[i] < wf[j] && hf[i] < hf[j])
mat[i][j] = 1, ++in[j];
else if (wf[i] > wf[j] && hf[i] > hf[j])
mat[j][i] = 1, ++in[i];
}
topo();
printf("%d\n", ans);
dfs(fin);
return 0;
}