Codeforces 4D
1823 ワード
#include<iostream>
#include<cstdio>
#include<string.h>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<vector>
using namespace std;
const int maxn = 5050;
class ev{
public:
int w, h, idx;
bool operator < (const ev& e) const {
if(w == e.w){
return h < e.h;
}
return w < e.w;
}
};
ev eev[maxn];
int dp[maxn];
int pprev[maxn];
int main(){
int n, w, h;
while(scanf("%d%d%d",&n,&w,&h)!=EOF){
memset(eev, 0, sizeof(eev));
memset(dp, 0, sizeof(dp));
memset(pprev, -1, sizeof(pprev));
int tmpw, tmph,idx = 0,cntev;
for(int i = 0; i < n; ++i){
cin >> tmpw >> tmph;
if(w >= tmpw || h >= tmph){
continue;
}
eev[idx].w = tmpw;
eev[idx].h = tmph;
eev[idx].idx = i;
idx++;
}
if(idx == 0){
cout << "0" << endl;
return 0;
}
cntev = idx;
sort(eev, eev + idx);
dp[0] = 1;
pprev[0] = -1;
for(int i = 1; i < idx; ++i){
dp[i] = 1;
for(int j = 0; j < i; ++j){
if(eev[j].w < eev[i].w && eev[j].h < eev[i].h && (dp[j] + 1) > dp[i]){
dp[i] = dp[j] + 1;
pprev[i] = j;
}
}
}
int recmax = -1, tmpmax = -1;
for(int i = 0; i < idx; ++i){
if(dp[i] > tmpmax){
tmpmax = dp[i];
recmax = i;
}
}
cout << tmpmax << endl;
bool first = false;
vector<int> vecint;
for(int ttmp = recmax; ttmp != -1; ttmp = pprev[ttmp]){
vecint.push_back(eev[ttmp].idx);
}
int vvecsize = vecint.size();
for(int kkk = vvecsize - 1; kkk >= 1; --kkk){
cout << vecint[kkk] + 1 << " ";
}
cout << vecint[0] + 1;
cout << endl;
}
return 0;
}