题目:传送门
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define deg(x) cout<< #x"=" << x << endl;
#define degg(x,y) cout<< #x"="<< x <<","<< #y"="<< y <<endl;
#define deggg(x,y,z) cout<<#x"="<<x<<","<<#y"="<<y<<","<<#z"="<<z<<endl;
#define sca(x) scanf("%d",&x)
#define scaa(x,y) scanf("%d%d",&x,&y)
#define scaaa(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define pch(x) putchar(x)
#define ptf(x) printf("%d\n",x)
#define ptff(x,y) printf("%d %d\n",x,y)
#define ptfff(x,y,z) printf("%d %d %d\n",x,y,z)
#define space(x) printf("%d ",x)
#define mes(a,x) memset(a,x,sizeof(a))
#define PI acos(-1)
#define lowbit(x) x&-x
#define ALL(X) (X).begin(), (X).end()
#define PB push_back
#define MP make_pair
#define ls rt<<1
#define rs rt<<1|1
#define X first
#define Y second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef priority_queue<int,vector<int>,greater<int> > xqueue;
typedef priority_queue<int> dqueue;
const ll mod=1e9+7;
const ll INF=9e18;
const int inf=2147483647;
const int N=1e3+5;
struct ok
{
int w,s,x;
bool operator<(const ok &b) const
{
return s>b.s;
}
}a[N];
int dp[N],pf[N];
void dfs(int x)
{
if(pf[x]<0)
{
ptf(a[x].x);
return;
}
dfs(pf[x]);
ptf(a[x].x);
}
void work()
{
int w,h;
int n=0;
while(~scaa(w,h))
{
a[n]=ok{w,h,n+1};
n++;
}
sort(a,a+n);
mes(pf,-1);
int ans=0,x;
dp[0]=1;
for(int i=1;i<n;i++)
{
dp[i]=1;
for(int j=0;j<i;j++)
{
if(a[j].w<a[i].w)
{
if(dp[i]<dp[j]+1)
{
dp[i]=dp[j]+1;
pf[i]=j;
}
}
}
if(ans<dp[i])
{
ans=dp[i];
x=i;
}
}
ptf(ans);
dfs(x);
}
int main()
{
work();
return 0;
}